java - Creating a class with a generic enum field. Enum field used to get enum's values -


i need class can give different enum types , in class need obtain values of given enum.

this how tried do, have issue defining type of enum field:

class myclass{   private class<t> enumtype; //how t?    void <t extends enum<t>> setenumtype(class<t> enumtype){      this.enumtype = enumtype;   }    void dosomething(){      (enum<t> literal : enumtype.getenumconstants()) {          // literal.name();      }   } } 

update: can't make class generic (myclass<t extends enum<t>>). need other solution.

something should work (however suggest pass enum class in constructor):

class myclass<t extends enum<t>> {   private class<t> enumtype;     void setenumtype(class<t> enumtype){      this.enumtype = enumtype;   }    void dosomething(){      (t literal : enumtype.getenumconstants()) {          // literal.name();      }   } } 

Comments

Popular posts from this blog

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

php - Magento - Deleted Base url key -

android - How to disable Button if EditText is empty ? -