since I have not used generics for some time, I'm rather confused in this example.
I have the following base abstract class:
public abstract class ExcelReader<T>{ protected T type; protected GenericResolver resolver; public ExcelReader(){ super(); resolver=ResolverFactory.createResolver(type.getClass()); } }
now my subclass is as follows:
public class POIReader<T> extends ExcelReader<T>{ }
Now in my service, I create a new object as follows:
ExcelReader<MessageDTO> reader=new POIReader<MessageDTO>();
However, when the ExcelReader constructor is called with the type attribute, it is null and throws a NullPointer exception in consecuence when creating the recognizer.
I think you can understand what I'm trying to do with the code snippets above, and I saw examples using the attribute field to save the type of the parameterized class.
However, I am completely confused by why I get null in the type attribute, and how I could avoid it. Thank you very much.
source share