M
Martin Lorentzson
I would like to determine the class value of a generic type. Is it
possible?
Right now, I'm passing the type as a parameter to the class
constructor:
public class Example<T extends Enum<T>> {
private final Class<T> clazz;
protected Example(Class<T> clazz) {
this.clazz = clazz;
}
public T parse(String text) {
// Can I derive the value of clazz from T?
T value = T.valueOf(clazz, text);
return value;
}
}
But I'm wondering if I can derive the class value of T instead of
using a constructor parameter or is type erasure as play here?
/Martin
possible?
Right now, I'm passing the type as a parameter to the class
constructor:
public class Example<T extends Enum<T>> {
private final Class<T> clazz;
protected Example(Class<T> clazz) {
this.clazz = clazz;
}
public T parse(String text) {
// Can I derive the value of clazz from T?
T value = T.valueOf(clazz, text);
return value;
}
}
But I'm wondering if I can derive the class value of T instead of
using a constructor parameter or is type erasure as play here?
/Martin