List<? extends Base> list
List<Base> list
Is there any difference between the two declarations?
Thanks,
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.
Yes.
List<Base>can contain a mixture of different things that all derive fromBase.List<? extend Base>contains homogeneous items (in the sense that they must all derive from some specific, unknown type that in turn derives fromBase).Put another way,
List<? extends Base>is the base class forList<T extends Base>. So you can pass aList<T extends Base>to any method that takes aList<? extends Base>. The same is not true for methods that take aList<Base>.