问题
I'm trying to implement a simple State of type FungibleAsset, even though it seems not that delicate, it gives a compilation error.
error: TestState is not abstract and does not override abstract method getAmount() in FungibleState public class TestState implements FungibleAsset {
error: getAmount() in TestState cannot implement getAmount() in FungibleState public Amount> getAmount() {
return type Amount> is not compatible with Amount> where T is a type-variable: T extends Object declared in interface FungibleState
public class TestState implements FungibleAsset<Currency> {
Amount<Issued<Currency>> amount;
AbstractParty owner;
@NotNull
@Override
public Amount<Issued<Currency>> getAmount() {
return amount;
}
@NotNull
@Override
public Collection<PublicKey> getExitKeys() {
return Arrays.asList(owner.getOwningKey());
}
@NotNull
@Override
public FungibleAsset<Currency> withNewOwnerAndAmount(@NotNull Amount<Issued<Currency>> newAmount, @NotNull AbstractParty newOwner) {
return null;
}
@NotNull
@Override
public AbstractParty getOwner() {
return owner;
}
@NotNull
@Override
public CommandAndState withNewOwner(@NotNull AbstractParty newOwner) {
return null;
}
@NotNull
@Override
public List<AbstractParty> getParticipants() {
return Arrays.asList(owner);
}
}
While implementing FungibleState works, I don't get what's exactly wrong, I do override required methods.
回答1:
FungibleAsset
interface already has a member calledamount
; no need to introduce your own.- The correct code would look like this:
import net.corda.core.contracts.Amount;
import net.corda.core.contracts.CommandAndState;
import net.corda.core.contracts.FungibleAsset;
import net.corda.core.contracts.Issued;
import net.corda.core.identity.AbstractParty;
import org.jetbrains.annotations.NotNull;
import java.security.PublicKey;
import java.util.Collection;
import java.util.Currency;
import java.util.List;
public class TestState implements FungibleAsset<Currency> {
@NotNull
@Override
public Amount<Issued<Currency>> getAmount() {
return null;
}
@NotNull
@Override
public Collection<PublicKey> getExitKeys() {
return null;
}
@NotNull
@Override
public FungibleAsset<Currency> withNewOwnerAndAmount(
@NotNull Amount<Issued<Currency>> newAmount,
@NotNull AbstractParty newOwner) {
return null;
}
@NotNull
@Override
public AbstractParty getOwner() {
return null;
}
@NotNull
@Override
public CommandAndState withNewOwner(@NotNull AbstractParty newOwner) {
return null;
}
@NotNull
@Override
public List<AbstractParty> getParticipants() {
return null;
}
}
来源:https://stackoverflow.com/questions/61100103/fungibleasset-implementation-in-java-wont-compile-corda-4-4