aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Creating Generic Classes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Creating Generic Classes" Watch "Creating Generic Classes" New topic
Author

Creating Generic Classes

Percy Dadabhoy
Greenhorn

Joined: Mar 26, 2007
Posts: 26
Consider the foll. from pg.602 from the Sierra-Bates exam. study guide-

public class AnimalHolder<T extends Animal> { // use "T" instead of "?"

T animal;

public static void main(String[] args) {
AnimalHolder<Dog> dogHolder = new AnimalHolder<Dog>(); // OK
AnimalHolder<Integer> x = new AnimalHolder<Integer>(); // NO!
}
}

It is mentioned that <T extends Animal> can be used to specify a bounds for the type. However, if I use <T super Animal>, it does not compile.

If the purpose of this construct is only to provide a way of bounding the type, why is it that I can't use super? Or, is it that there is no practical purpose to super which I am failing to see?

Regards
Percy
Chandra Bhatt
Ranch Hand

Joined: Feb 28, 2007
Posts: 1707
Check this link


Discussed same issue

and

Similar issue
[ May 26, 2007: Message edited by: Chandra Bhatt ]

cmbhatt
 
 
subject: Creating Generic Classes