问题
This has been asked here but I will try to approach the question differently.
A quick review of Corda's code:
interface FungibleState<T : Any> : ContractState {
val amount: Amount<T>
}
FungibleAsset then extends FungibleState:
interface FungibleAsset<T : Any> : FungibleState<Issued<T>>, OwnableState {
override val amount: Amount<Issued<T>>
@get:SerializableCalculatedProperty
val exitKeys: Collection<PublicKey>
fun withNewOwnerAndAmount(newAmount: Amount<Issued<T>>, newOwner: AbstractParty): FungibleAsset<T>
}
If I use FungibleAsset in a Java CorDapp:
public class MyFungibleAsset implements FungibleAsset<Currency> {
@NotNull
@Override
public Amount<Issued<Currency>> getAmount() {
return null;
}
...}
it will raise 2 errors when I build the project (IntelliJ won't highlight any error during editing):
error: MyFungibleAsset is not abstract and does not override abstract method getAmount() in FungibleState
error: getAmount() in MyFungibleAsset cannot implement getAmount() in FungibleState
public Amount<Issued<Currency>> getAmount() {
^
return type Amount<Issued<Currency>> is not compatible with Amount<Issued<? extends Currency>>
where T is a type-variable:
T extends Object declared in interface FungibleState
I assume this has something to do with FungibleState's getAmount returning Amount<T>
whereas FungibleAsset's getAmount returns Amount<Issued<T>>
? I don't get an error in kotlin.
来源:https://stackoverflow.com/questions/62925386/is-fungibleasset-compatible-with-java-cordapps