wood burning stoves 2.0*
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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
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: 18498
    
  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!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: why not super in generic method declaration
 
Similar Threads
Generics question
Generic type declaration
question about the generic methods : ExamLab final test
A bunch of questions on different topics
need help about generics