Open kobi26c opened 2 years ago
Hi kobi26c,
I'm not 100% sure what you're trying to achieve. But after replacing Object
with ActionClass
and removing @GenericEnumParam
, the class compiles.
@GenericEnum
public enum Test implements ActionFactory<ActionClass> {
FEATURE_FLAGS(AActionClass.class, a -> new AActionClass()),
NOT_FEATURE_FLAGS(BActionClass.class, b -> new BActionClass());
private final ActionFactory<ActionClass> constructor;
Test(Class<? extends ActionClass> actionClass, ActionFactory<ActionClass> constructor) {
this.constructor = constructor;
}
@Override
public ActionClass getAction(String s) {
return constructor.getAction(s);
}
}
which allows you to do
ActionClass a = Test.FEATURE_FLAGS.getAction("a");
Hope this helps, Simon
Thanks for replying!
I don't want to work with ActionClass as an interface I want to be able to get the explicit action implementation (T) from the getAction method
Hi kobi26c,
Ok this is the closest I can get. Not as concise.
@GenericEnum
public enum Test {
FEATURE_FLAGS(AActionClass.class) {
@Override
public AActionClass getAction(String s){
return new AActionClass();
}
},
NOT_FEATURE_FLAGS(BActionClass.class) {
@Override
public BActionClass getAction(String s){
return new BActionClass();
}
};
Test(Class<? extends ActionClass> actionClass) {
}
public abstract @GenericEnumParam("T") Object getAction(String s);
}
Allows you to do:
AActionClass a = TestExt.FEATURE_FLAGS.getAction("a");
This is a modified version of the org.cmoine.genericEnums.AbstractEnum sample.
Simon
I saw that implementation and wanted to avoid it When having over 100 enum types its not so fun :) But thanks a lot for the help
Hi! Very cool feature I must say!
I'm trying to achieve something but I can seem to make it work. This is my example:
This is the ActionFactory class:
After compile it creates TextExt with some errors:
The constructor variable is
ActionFactory<@GenericEnumParam() Object>
instead ofActionFactory<T>
private TestExt(Class<? extends ActionClass> actionClass, ActionFactory<@GenericEnumParam() Object>
Am I missing anything ? is this something I can achieve with current implementation or it's a new feature need to develop ?
Thanks!!