This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

why not super in generic method declaration

 
zhong chen
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This script is from examlab final:



My question, if I change the method declaration from <T extends E> to <T super E>, it won't compile. Why not?
 
Leandro Coutinho
Ranch Hand
Posts: 423
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think the super keyword only accepts the wildcard as the left operand.
Am I right?
 
Henry Wong
author
Marshal
Pie
Posts: 20904
76
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
zhong chen wrote:
My question, if I change the method declaration from <T extends E> to <T super E>, it won't compile. Why not?


Let's assume, for a moment, that <T super E> is allowed. What would that get you? You code will need to handle any Object type, as Object is a super of E, so how is that different from not using method generics?

Henry
 
zhong chen
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank make sense. Thanks to you both!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic