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

Objective 7.6 Java Operators (instanceof) Operator

 
John Paterson
Ranch Hand
Posts: 171
  • 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.
 
John Jai
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?

 
Helen Ma
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.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic