GeeCON Prague 2014*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes why not super in generic method declaration Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "why not super in generic method declaration" Watch "why not super in generic method declaration" New topic
Author

why not super in generic method declaration

zhong chen
Greenhorn

Joined: Oct 12, 2009
Posts: 24
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

Joined: Mar 04, 2009
Posts: 417
I think the super keyword only accepts the wildcard as the left operand.
Am I right?
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18876
    
  40

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


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
zhong chen
Greenhorn

Joined: Oct 12, 2009
Posts: 24
Thank make sense. Thanks to you both!
 
GeeCON Prague 2014
 
subject: why not super in generic method declaration