This week's book giveaway is in the Artificial Intelligence and Machine Learning forum.
We're giving away four copies of Succeeding with AI and have Veljko Krunic on-line!
See this thread for details.
Win a copy of Succeeding with AI this week in the Artificial Intelligence and Machine Learning forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
  • Junilu Lacar
Sheriffs:
  • Tim Cooke
  • Jeanne Boyarsky
  • Knute Snortum
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • salvin francis
  • fred rosenberger
  • Frits Walraven

Objective 7.6 Java Operators (instanceof) Operator

 
Ranch Hand
Posts: 173
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Friends,

I have some difficulty in understanding a particular row in Table 4.1 from Kathy Sierra SCJP 6 book. The table is in page 298.

In row 5, Foo[] is compared against Foo, Bar and Face with the instance of operator and the result is false. What I don't undserstand is in row 7, Foo[1] is compared against Foo, Bar, Face Object and this time the reslt is True??? I don't understand why. Hope somebody can help out. The code on which all this is based is as follow:




Thanks.
 
Rancher
Posts: 1776
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

John Paterson wrote:In row 5, Foo[] is compared against Foo, Bar and Face with the instance of operator and the result is false.


I don't have the book so I may be missing something. Anyways, I was not at all able to compare between Foo[] type against Foo. I received a compilation error. How do you got instanceof returning false?

Can you show the operator code?

 
Ranch Hand
Posts: 451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

John Paterson wrote:
In row 5, Foo[] is compared against Foo, Bar and Face with the instance of operator and the result is false. What I don't undserstand is in row 7, Foo[1] is compared against Foo, Bar, Face Object and this time the reslt is True??? I don't understand why. Hope somebody can help out. The code on which all this is based is as follow:






Foo[1] refers to an object of Foo type. For example Foo[1] = new Foo();
Is Foo[1] an instance of Foo? True
Is Foo[1] an instance of Bar? True
Is Foo[1] an instance of Face? True
Is Foo[1] an instance of Object? True

Foo[] is an array. It is an instance of Object, but it is not an instance of Foo, Bar or Face.

 
    Bookmark Topic Watch Topic
  • New Topic