Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

question about ==

 
Andres Gonzalez
Ranch Hand
Posts: 1561
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When using == to compare reference variables, the compiler will verify that the classes are the same or in the same inheritance hierarchy, otherwise it'll throw a compiler error

can you guys provide example(s) of this statement? specially when the compiler might throw a compilation error...
 
Alton Hernandez
Ranch Hand
Posts: 443
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Miki Muzsi
Ranch Hand
Posts: 120
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Andres, is exactly the same as with the instanceof operator or casting. If in the above example you try:
if (d instanceof D2) {} // compiler error!
or:
d = (D2) d2; // compiler error!
They must be in the same inheritence hierarchy.
Miki
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic