java - using enum (as type) in generic class and looping through its elements -


I have a normal class with the enum type as a normal type, and I then through all the elements in the enum I want to Hope the following example (not working) will make me more clear what I want. What is the correct syntax?

  Public Class Generic Class & lt; T xmax ant & lt; T & gt; & Gt; {T myEnum; Public zero doSomething (for (T element: myEnum.values ​​()) {// <- value () is not available ....}}}  

I will use the class

  generic class  manager; manager.doSomething ();  
< P>

You are trying to capture the context of example which of an enum is not very useful, but you need Can you pass the enum class to the constructor (which is called type token )

With a class, you can use the class (typed) method (which gives null if the class is not an enum square, but we It has been compiled as an enum class).

This compiled:

  public class generic class  Enum  T & gt; & Gt; {class  enumClass; public generic class (class  enumClass) {this.enumClass = enumClass;} public zero doSomething (for (T element: enumClass. GetEnumConstants ()) {}}}  

Comments