Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization 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:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

instanceof operand  RSS feed

 
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!