In the code below:
public class AvroReader<T> {
public AvroReader(Class type, File packetFile) throws IOException{
reader = new DataFileReader<>(packetFile,
new ReflectDatumReader<T>(ReflectData.get().getSchema(type)));
}
}
I'd like to do away with the field "type" in the constructor because type=T.class. If only the compiler accepted getSchema(T.class) !
One suggestion was to use:
Class<T> cls = (Class<T>) ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments()[0];
I get this error:
java.lang.Class cannot be cast to java.lang.reflect.ParameterizedType