Despite using generics, you still need to pass Class as an argument if you want to get a new instance of T.
public T get(Class<T> clazz, long nip) throws InstantiationException, IllegalAccessException {
T myT = cache.getFromMap(nip);
if (myT == null) {
T newT = clazz.newInstance();
putT(newT);
return newT;
} else
return myT;
}
Then you call it like this:
.get(SomeTaxable.class, someNip)
source
share