Java enums are great. So are generics. Of course we all know the limitations of the latter because of type erasure. But there is one thing I don\'t understand, Why can\'t I
This is now being discussed as of JEP-301 Enhanced Enums. The example given in the JEP is, which is precisely what I was looking for:
enum Argument { // declares generic enum
STRING(String.class),
INTEGER(Integer.class), ... ;
Class clazz;
Argument(Class clazz) { this.clazz = clazz; }
Class getClazz() { return clazz; }
}
Class cs = Argument.STRING.getClazz(); //uses sharper typing of enum constant
Unfortunately, the JEP is still struggling with significant issues: http://mail.openjdk.java.net/pipermail/amber-spec-experts/2017-May/000041.html