This week's book giveaway is in the Design forum.
We're giving away four copies of Building Microservices and have Sam Newman on-line!
See this thread for details.
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 Building Microservices this week in the Design 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: 423
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: 20057
    
  44

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’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
 
subject: why not super in generic method declaration
 
It's not a secret anymore!