Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Creating Generic Classes

 
Percy Dadabhoy
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1710
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check this link


Discussed same issue

and

Similar issue
[ May 26, 2007: Message edited by: Chandra Bhatt ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic