Can any body explain this generic vector Vector<? super Object> list = ... and where to use it?
Can any body explain this generic vector Vector<? super Object> list = … and
Share
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.
Here you are defining the lower bound of your unknown object
?. So theVector<? super Objectcan contain onlyObjectand any super class ofObject. But sinceObjectdoes’nt have a super class it has no sense. It behaves same asVector<Object>.Refer this sample.
The counterpart for this is upper bound
Vector<? extends Object>where you can add any object that extendsObject.You should be able to avoid using
Objectas the generic type is most cases.