• Post Reply Bookmark Topic Watch Topic
  • New Topic

instanceOf Compiler error  RSS feed

 
Jai Mani
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


why is there a compiler error ?
it should evaluate to false right ?

Or is it that the instance of just works in the same hierarchy.

Thanks For your help
 
Rajkamal Pillai
Ranch Hand
Posts: 445
1
Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the "compiler error"?
 
Jai Mani
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Campbell Ritchie
Marshal
Posts: 56536
172
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The compiler often produces errors from instanceof when it is obvious that the test is guaranteed to fail. There is no way a Cat object can be cast to Dog, and even the javac tool can tell that, so there is an error.
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you do this ?

no right? here what I am trying to say is instanceof operator requires object realation like casting. else compiler will complain.
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oops! campbell beaten me
 
Campbell Ritchie
Marshal
Posts: 56536
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Seetharaman Venkatasamy wrote:Oops! campbell beaten me
...and only by 41 seconds. But your post added something useful
 
Jai Mani
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank You O Kind people of the Ranch !!!

 
Campbell Ritchie
Marshal
Posts: 56536
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!