This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Final class can't be used on left side of instanceof operator ?/

 
vishal mishra
Ranch Hand
Posts: 103
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Namaste Friends !!

why program given below is giving compile time error??




Please Explain.....
Thanks
 
Stuart A. Burkett
Ranch Hand
Posts: 679
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Java compiler is clever enough to know that E could never be an instance of I, so it doesn't allow that statement.
 
vishal mishra
Ranch Hand
Posts: 103
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Stuart A. Burkett wrote:The Java compiler is clever enough to know that E could never be an instance of I, so it doesn't allow that statement.


Thank You Friend !! Got it !!
 
Arnab Sunny Rakshit
Greenhorn
Posts: 19
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the final class implements interface I then compiler will be happy.

In my opinion. Compiler allows only objects and classes in the same hierarchy (if obvious to compiler)to be used with the instanceof operator. I said "obvious to compiler" because compiler allows this --
new ArrayList () instanceof I

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic