vendredi 4 octobre 2019

How to get instance of arbitrary Enum from name as String

Assume I have various Enums with a few constants

public enum MyEnum1 {

ConstantA(),
ConstantB(),
ConstantC();

}
public enum MyEnum2 {

ConstantA(),
ConstantB(),
ConstantC();

}

How can I get an instance of one of these enums arbitrarily from it's name so that I can invoke Enum.values() on.

Something like: Enum<?> myEnumInstance = //somehting

The goal is to invoke .values() to find and retrieve data inside the constants on said arbitrary enum based on user text input.





Aucun commentaire:

Enregistrer un commentaire