Enum.valueOf() cannot be hidden by another static valueOf specific Enum type, but since I create my objects with reflection from text files, I need a general way to call valueOf .
Currently, my Enum has a static fromString() class:
public enum Fruits { APPLE, ORANGE, ...; public static Fruit fromString(String fruit) { ... } }
But how can I associate such a method when, when I deal with the enum field type, I call the appropriate method? The only thing I can think of:
- using marker interface
- implement this static method for each enumeration
- invoke a static method using reflection
Is there any other alternative that limits this restriction?
source share