File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

instanceof operand

 
Ashwin Kumar
Ranch Hand
Posts: 78
  • 0
  • 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
  • 0
  • 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 ??
 
Animesh Shrivastava
Ranch Hand
Posts: 298
  • 0
  • 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
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic