What’s the difference between:
SomeClass<T extends OtherClass>
and
SomeClass<T super OtherClass>
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.
Sun says (from Using and Programming Generics in J2SE 5.0)
More Fun with Wildcards gives some good examples to all three types.
Another good example (taken from the video recommended by @Adrian) is:
Here you can see the difference between
superandextends:For the method
pushAllimagine you have aStack<Number>. You want to push all elements ofsrcto theStack. Butsrcshould be able to be aCollection<Integer>. This is why you choose? extends Ehere.For the method
popAllimagine you have aStack<Integer>. You want to pop all elements of theStacktodest. Butdestshould be able to be aCollection<Number>. This is why you choose? super Ehere.