-
Notifications
You must be signed in to change notification settings - Fork 33
Closed
Labels
Description
sorry if this is already present, did not find it.
I already have this code in a common class :
class A {
A(MyEnum param){}
}
I want to use JCodeModel to create the class B:
class B extends A{
B(){
super(MyEnum.enum1);
}
}
I create the definedclass bclass, create the constructor, but when I want to set super(enum1) I need to call JExpr.enumConstantRef(cm.ref(MyEnum.class), enum1.name())
I think it would be easier to add an enumRef in JCodeModel that allow to refer to an enum constant more easily.
eg
/**
* refer to clazz.ref
*/
public <T extends Enum<T>> JEnumConstantRef enumRef(Class<T> clazz, T ref) {
return JExpr.enumConstantRef(ref(clazz), ref.name());
}
(did not test this code, maybe the idea is bad - it compiles but :P )
phax