Only 48 hours left in the trailboss' kickstarter!

New rewards and stretch goals. CLICK HERE!



  • Post Reply Bookmark Topic Watch Topic
  • New Topic

why not super in generic method declaration  RSS feed

 
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
Sheriff
Posts: 22814
119
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
Boost this thread!