Type erasure is the process of removing generic information for backward compatibility on compiled class. Then, I can't know what type of class are the objects in a generic class, but in an inherited class, for example:
package generics.testing;
class Box<T> {
private T value;
public Box() {
System.out.println("GenericSuperClass: " + getClass().getGenericSuperclass());
}
public T getValue() {
return value;
}
public void setValue(T value) {
this.value = value;
}
}
class IntegerBox extends Box<Integer> {}
public class GenericsTesting {
public static void main(String[] args) {
Box<String> box = new Box<>();
IntegerBox ibox = new IntegerBox();
}
}
I get:
GenericSuperClass: class java.lang.Object
GenericSuperClass: generics.testing.Box<java.lang.Integer>
My question is, why is that information generics.testing.Box<java.lang.Integer>
preserved and where is stored?