I have a base configuration class that provides all possible keys and the type of the corresponding value types in an enumeration, for example:
public class Configuration {
public static enum Key {
FIRST_KEY("actual key 1", Long.class),
ANOTHER_KEY("actual key 2", Integer.class)
public final String value;
public final Class type;
Key(String value, Class type) {
this.value = value;
this.type = type;
}
}
}
What I would like to do is write a method that parses the value of the given key from String and returns the value as the appropriate type. Mainly:
public <T> T getValue(Key<T> key, String valueStr);
This attempt failed in the method declaration, as a message appears stating that Enums in Java cannot have type arguments. Any ideas on how to achieve something like this?
source
share