I am tying to save the Type of a generic value, because i can't get it at runtime:
public class A<T> {
private final Class<T> genericType;
public A(Class<T> genericType) {
this.genericType = genericType;
}
public Class getGenericType() {
return genericType;
}
}
To make subclasses now, I use it as follows:
public class B extends A<String> {
public B() {
super(String.class);
}
}
Note thet the super()'s parameter type matches (by compile timne check) to the A's generic type. That works fine. But if i want to have it with a Map, i cannot get the correct class object:
public class C extends A<Map<String, String>> {
public C() {
super(Map.class); // does not match Map<String,String>
super(Map<String,String>.class) // no valid java expression, i dont know what
}
}
Sooo anyone got a tip to help me out of this misery? Best i could do currently, is to give up the strong typing in A:
public class A<T> {
// old: private final Class<T> genericType;
private final Class genericType; // note the missing generic
public A(Class genericType) { // here as well
this.genericType = genericType;
}
public Class getGenericType() {
return genericType;
}
}