• 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

instanceof operand

 
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please clarify the following

Operands and Results Using instanceof Operator

First operand instanceof operand Result

1) Foo[] Foo,Bar,Face false

2) Foo[1] Foo,Bar,Face,Object true

Can anyone explain why the second one returns true when tested for instanceof operands given ??
 
Ashwin Kumar
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please ignore the above question here is modified message ..

Please clarify the following




Operands and Results Using instanceof Operator

1)

First operand - Foo[]

instanceof operand - Foo,Bar,Face

Result - false


2)

First operand - Foo[1]

instanceof operand - Foo,Bar,Face

Result - true


Can anyone explain why the second one returns true when tested for instanceof operands given ??
 
Ranch Hand
Posts: 298
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Foo[] can contain objects of Foo or its subclasses
When u do Foo[1] , u have in it contained either a Foo object or any of its subclass.

U can also have this done:
Face fc = Foo[1];// Because Face is a super interface of the Foo object
Bar br = Foo[1]; // Bar is Foo's super class, so thats ok

So thats the reason for ur second output.

1) Now for the first question keep in mind this:
Foo[] extends (Object, Object[]) and not Foo, Bar or Face

I hope this is ok
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic