I have a couple of questions about generic wildcards in Java:
-
What is the difference between
List<? extends T>andList<? super T>? -
What is a bounded wildcard and what is an unbounded wildcard?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
In your first question,
<? extends T>and<? super T>are examples of bounded wildcards. An unbounded wildcard looks like<?>, and basically means<? extends Object>. It loosely means the generic can be any type. A bounded wildcard (<? extends T>or<? super T>) places a restriction on the type by saying that it either has to extend a specific type (<? extends T>is known as an upper bound), or has to be an ancestor of a specific type (<? super T>is known as a lower bound).The Java Tutorials have some pretty good explanations of generics in the articles Wildcards and More Fun with Wildcards.