• 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

Generics and collections K&B pg 526

 
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi.. i have a doubt in the following code:


// i did not understand "o instanceof Moof"... how come object IS A Moof... object is a superclass... and there is no Moof object assigned to 'o'..
thanks...
 
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Every object inherits the equals() method from the Object class. You can then override it to carry out whichever equality tests are required for the class.

What this means is that you must use the same method signature as the Object class. This isn't a problem as every class extends from the Object class therefore every object IS-A Object. Even though the variable o is declared as being of type Object it is still a Moof object. However, in order to access any Moof members you need to first cast it to a Moof object.

Before you try treating o as a Moof object you must first check that it is indeed a Moof object. If it was for example a Dog object and you try accessing a Moof method you would get a ClassCastException.
 
sweety singh
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks...
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic