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
The answer is in the question:
because of type erasure
None of these two methods are possible, since the argument type is erased.
public T getValue(MyEnum param);
public T convert(Object);
To realise those methods you could however construct your enum as:
public enum MyEnum {
LITERAL1(String.class),
LITERAL2(Integer.class),
LITERAL3(Object.class);
private Class> clazz;
private MyEnum(Class> clazz) {
this.clazz = clazz;
}
...
}