Why do I need to cast the return of obj.getClass() to a Class<T> type when obj has type T? This also generates a warning, which I have silenced. But I feel like this shouldn't be necessary. What's going on here?
public class DataSerialization<T> {
private T deserializedObject;
private Class<T> classObject;
private String serializedObject = null;
private static final Gson gson = new Gson();
@SuppressWarnings("unchecked")
public DataSerialization(T obj) {
this.deserializedObject = obj;
this.classObject = (Class<T>) obj.getClass();
}
// ...
}