Home >Java >javaTutorial >What's the Difference Between `List
Question 1: What is the distinction between List extends T> and List super T>?
Answer:
Both List extends T> and List super T> are examples of bounded wildcards. An unbounded wildcard is represented as >, similar to extends Object>. This implies that the generic type can be any type without specific constraints.
In contrast, bounded wildcards restrict the type. List extends T> is known as an upper-bounded wildcard. It signifies that the generic type must extend T. For instance, List extends String> can hold any list that contains subclasses of String (e.g., List
List super T> is known as a lower-bounded wildcard. It specifies that the generic type must be an ancestor of T. For example, List super String> can hold any list that contains superclasses of String (e.g., List
The above is the detailed content of What's the Difference Between `List. For more information, please follow other related articles on the PHP Chinese website!