FungibleAsset implementation in Java won't compile (Corda 4.4)

£可爱£侵袭症+ 提交于 2021-01-28 19:33:49

问题


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 called amount; 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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!