Reputation: 164
Is it possible to define an @InitiatingFlow as a generic class?:
@InitiatingFlow
public class FungibleStateIssueSend<T extends Oil> extends FlowLogic<SignedTransaction> {...}
...If I try I get a compile error on the @InitiatedBy annotation in the receiving flow:
@InitiatedBy(FungibleStateIssueSend.class)
public class FungibleStateIssueReceive extends FlowLogic<Void> {...}
Error:
Incompatible types. Found: 'java.lang.Class<com.template.flows.FungibleStateIssueSend>', required: 'java.lang.Class<? extends net.corda.core.flows.FlowLogic<?>>'
Here is how I was going to use it:
// Define the delivery unit (bbl, m3 or tonne) and corresponding API of the oil in that unit:
WtiBbl wtiBbl = new WtiBbl(new BigDecimal("4.5"));
// Set Amount of units for delivery:
Amount<WtiBbl> amountWtiBbl = new Amount<>(1_000L, wtiBbl);
// Create a FungibleState so the delivery can be divided between different shippers:
OilFungibleState<WtiBbl> juneProduction = new OilFungibleState<>(Month.JUNE, Collections.singletonList(partyA), amountWtiBbl);
// Issue the FungibleState onto the ledger...
FungibleStateIssueSend<WtiBbl> fungibleStateIssueSend = new FungibleStateIssueSend<>(juneProduction);
CordaFuture<SignedTransaction> future = partyANode.startFlow(fungibleStateIssueSend);
mockNetwork.runNetwork();
SignedTransaction signedTransaction = future.get();
I can work around the limitation. I just want to understand if this is a Corda thing or a Java thing?
Upvotes: 0
Views: 69
Reputation: 1821
It feels like its more of a Java thing.
For example, if I use a wild card for the class type it works fine with generic typed parameter.
@Target(ElementType.TYPE_USE)
@Retention(RetentionPolicy.RUNTIME)
@interface TestAnnotation{
public Class<?> value();
}
So I can use the annotation @TestAnnotation(Initiator.class)
in a class, while Initiator could be defined as:
public static class Initiator<T> extends FlowLogic<SignedTransaction>
But when we bound the wildcard to something below, the compiler complains.
@Target(ElementType.TYPE_USE)
@Retention(RetentionPolicy.RUNTIME)
@interface TestAnnotation{
public Class<? extends FlowLogic<?>> value();
}
But if we remove the wildcard from the FlowLogic it works. Not sure why the compiler complains because of that wildcard.
Upvotes: 1