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
Post a Comment