I am a new java learner. Recently I was reading Generic programming and got my self confused with this…
A<T extends B> and A<? extends B>
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.
First of all, those are completely different constructs used in different contexts.
A<T extends B>is a part of generic type declaration such asIt declares generic type
Awith type parameterT, and introduces a bound onT, so thatTmust be a subtype ofB.A<? extends B>is a parameterized type with wildcard, it can be used in variable and method declarations, etc, as a normal type:Variable declaration such as
A<? extends B> ameans that type ofaisAparameterized with some subtype ofB.For example, given this declaration
you can:
Assign a
Listof some subtype ofNumbertol:Get an object of type
Numberfrom that list:However, you can’t put anything into list
lsince you don’t know actual type parameter of the list: