File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Creating Generic Classes" Watch "Creating Generic Classes" New topic

Creating Generic Classes

Percy Dadabhoy

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?

Chandra Bhatt
Ranch Hand

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

Discussed same issue


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

I agree. Here's the link:
subject: Creating Generic Classes
It's not a secret anymore!