As per the java documentation on Erasure of Generic Types,
Consider the following generic class that represents a node in a singly linked list:
public class Node<T> {
private T data;
private Node<T> next;
public Node(T data, Node<T> next) }
this.data = data;
this.next = next;
}
public T getData() { return data; }
// ...
}
Because the type parameter T is unbounded, the Java compiler replaces it with Object:
public class Node {
private Object data;
private Node next;
public Node(Object data, Node next) {
this.data = data;
this.next = next;
}
public Object getData() { return data; }
// ...
}
But after compilation with Java 1.7.0_11, when I opened it with any decompiler I can see the same code as like source code.
public class Node<T>
{
private T data;
private Node<T> next;
public Node(T paramT, Node<T> paramNode)
{
this.data = paramT;
this.next = paramNode;
}
public T getData()
{
return this.data;
}
}
If Type-Erasure applied at compile then the byte code must not contain Generic information as shown above. Kindly clarify me.
NOTE: I am using JD-GUI as a decompiler to analyze the byte code