• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Collections with hierarchical type parameter

 
timo corn
Ranch Hand
Posts: 68
MyEclipse IDE PHP Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Is the following correct:
-Grass and Plant have nothing to do here
-Sheep is a animal and eats plants (why is there "<sheep>" as Herbivore type?). Sheep eat sheep?
-Wolf is a animal and eats meat (sheeps)
-Interfaces Carnivores and Herbivores are of type hungry, so they are hungry
 
Henry Wong
author
Marshal
Pie
Posts: 21418
84
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
 
Himai Minh
Ranch Hand
Posts: 1316
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Is the following correct:
-Grass and Plant have nothing to do here
-Sheep is a animal and eats plants (why is there "<sheep>" as Herbivore type?). Sheep eat sheep?
-Wolf is a animal and eats meat (sheeps)
-Interfaces Carnivores and Herbivores are of type hungry, so they are hungry

I know this is from the self-test in KB's book.
What is your question regarding to this self test question? If you don't understand the explanation in the self-test, let us know.

Why is there <Sheep> as Herbivore type?

Herbivore <E extends Animal> means Herbivore take an Animal as its generic parameter. Sheep is an animal. So, Herbivore<Sheep> compiles.

 
timo corn
Ranch Hand
Posts: 68
MyEclipse IDE PHP Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So is sheep an animal that eats plants and wolf an animal that eats meat? Normally, classes and interfaces do not make sense in the ocjp, but I think in this example you HAVE to understand the class behaviour? Am I right?

I do not understand the implementations Carnivore<sheep> and Herbivore<Sheep>. Should be Carnivore<an aggressive animal like a wolf>?

Henry, the example is taken from kb, self test, chapter collections.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic