The Java enums value is used with generics
•
Java
I need something like this:
public enum Enum { ENUM1<Class1>(Class1.class,"A DESCRIPTION",new Class1()),ENUM2<Class2>(Class2.class,new Class2()),ENUM3<Class3>(Class3.class,new Class3()); private Enum(Class<? extends Object> clazz,String description,Object instance) {} }
What I need: I define a single place for different instances of all classx (they extend the same classsuper) Of course, I can define different enumerations for each classx, but that's not what I want
Solution
JLS does not allow enumerated type parameters:
EnumDeclaration: ClassModifiers(opt) enum Identifier Interfaces(opt) EnumBody EnumBody: { EnumConstants(opt),(opt) EnumBodyDeclarations(opt) }
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码