What's the difference between the following type definitions
<E extends Number>
and
<? extends Number>
Cheers, Don
This version:
<? extends Number>
can appear in a non-generic method/type, and it basically means "I don't care what the type is, so long as it derives from Number
. I'm not going to really use the type, I just need it to be appropriate."
This version:
<E extends Number>
requires E to be a type parameter. It allows you to do more (for instance, creating an ArrayList<E>
later on) but the extra type parameter can make things more complicated when you don't really need them to be.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.