My Java Generics is rusty returning to Java after a long time away.
I am trying to create a generic base class to wrap Jacksons ObjectMapper
abstract class MyBaseClass<T> {
private Class<T> clazz;
public void read() {
objectMapper.readValue(json, clazz)
}
abstract Class<T> getGenericTypeClass();
}
The issue I am having is that sometimes T is an instance of a class, and sometimes it needs to be List<T>
. My code works for the former, but I can't get it to compile when I have the list scenario. So this
class Sub extends MyBaseClass<Thing> {
@Override
getGenericTypeClass() {
return Thing.class;
}
}
works fine, but when I need List<Thing>
I'm a bit lost.