• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Collections with hierarchical type parameter

 
Ranch Hand
Posts: 68
MyEclipse IDE PHP Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Please QuoteYourSources.
 
Bartender
Posts: 2418
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic