java - Store enum class reference -


ok have 2 enums:

    public enum anotherenum     {         value1, value2, value3;     }      public enum myenum implements myinterface     {         value1(anotherenum);          generic_reference_type a;          myenum ( ?? )         {             = ??         }          getgenericreference()         {             return this.a;         }     } 

i want myenum store reference anotherenum class i'll able this:

    myenum.value1.getgenericreference().values(); 

is possible?

if i'm reading question correctly. pass different generic type each instance of enum... can't that, because every instance of enum same class, can generic, if generic must have same generic parameter.

however, can close intention basing code around enum class, expressed class<? extends enum<?>>:

public enum anotherenum {     a, b, c; }  public enum yetanotherenum {     x, y, z; }  public interface myinterface {     public enum<?>[] getgenericreferencevalues(); }  public enum myenum implements myinterface {     value1(anotherenum.class),     value2(yetanotherenum.class);      final class<? extends enum<?>> a;      private myenum(class<? extends enum<?>> a) {         this.a = a;     }      public enum<?>[] getgenericreferencevalues() {         return a.getenumconstants();     } } 

and see working:

public static void main(string[] args) {     system.out.println(arrays.tostring(myenum.value1.getgenericreferencevalues()));     system.out.println(arrays.tostring(myenum.value2.getgenericreferencevalues())); } 

output:

[a, b, c] [x, y, z] 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -