Here's the relevant code:
public interface Artifact {}
public interface Bundle implements Artifact {}
public interface Component implements Artifact {}
public interface State<T extends Artifact> {
void transition(T artifact, State<T> nextState);
}
This allows me to define this enum:
enum BundleState implements State<Bundle> {
A, B, C;
public void transition(Bundle bundle, State<Bundle> nextState) {}
}
}
But the method signature that I want is:
public void transition(Bundle bundle, BundleState nextState) {}
}
But this does not compile. Obviously the problem lies with how I've defined T
in the State
interface, but I can't figure out know how to fix it.
Thanks, Don
Things might start getting unwieldly, but you could change State
to:
public interface State<T extends Artifact, U extends State<T, U>> {
void transition(T artifact, U nextState);
}
And change BundleState to:
public enum BundleState implements State<Bundle, BundleState> {
A, B, C;
public void transition(Bundle bundle, BundleState nextState) {}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With