• 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:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

question about ==  RSS feed

 
Ranch Hand
Posts: 1561
  • 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...
 
Ranch Hand
Posts: 443
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Ranch Hand
Posts: 120
  • 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
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!