Consider this example: -
Case 1 Upper bound:
public class Node<T extends Comparable<T>> { private T data; private Node<T> next; }
In this case, the erasure type replaces the associated parameter T with the first class of Comparable boundaries.
public class Node { private Comparable data; private Node next; }
As we know, a reference to a Parent class can be used to refer to an object of a child class . Thus, this code is acceptable since the data link may point to a Comparable instance or its child classes.
Case 2 Lower bound:
If we have code similar to
public class Node<T super Comparable<T>> { private T data; private Node<T> next; }
In this case, Compiler cannot use Object or any other class to replace the associated type T here, and it is also impossible that a reference to a child class can be used to refer to an instance of the parent class.
source share