This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Need explain instanceof operator issue

 
matej spac
Greenhorn
Posts: 28
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I do not understand why instanceof operator is working as it is working. For example:


cause compilation error - this is clear, there is no IS-A relationship, Dog never ever could be a Cat.
But another example behaviour is weird for me:


works fine. It compiles and also run (and produce false of cource).
So tell me, in which universe Robot could be an Animal?
Why this don't cause compile error?

 
Paul Clapham
Sheriff
Pie
Posts: 20187
26
MySQL Database
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There could be a subclass of Robot which implements Animal. The compiler sees a variable of type Robot; this could be a reference to an instance of that subclass.

Try declaring the Robot class as "final" and see what changes.
 
matej spac
Greenhorn
Posts: 28
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
wow, so briefly and so clearly :-)
thanks, now I understand
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic