This week's book giveaway is in the Performance forum.
We're giving away four copies of The Java Performance Companion and have Charlie Hunt, Monica Beckwith, Poonam Parhar, & Bengt Rutisson on-line!
See this thread for details.
Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Generic type T

 
P Ventura
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's the following code legal?
 
Kelvin Chenhao Lim
Ranch Hand
Posts: 513
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, the argument syntax is incorrect. The "<? extends T>" wildcard syntax only applies if you're providing it as a type parameter for another generic class, e.g.



However, what you probably intended to do was simply this:



As per the usual rules of polymorphism, any object that's a subclass of T will be permitted wherever a T parameter is required.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic