File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Final class can't be used on left side of instanceof operator ?/ Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of JavaScript Promises Essentials this week in the JavaScript forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Final class can Watch "Final class can New topic
Author

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

vishal mishra
Ranch Hand

Joined: Jul 12, 2010
Posts: 103

Namaste Friends !!

why program given below is giving compile time error??




Please Explain.....
Thanks
Stuart A. Burkett
Ranch Hand

Joined: May 30, 2012
Posts: 679
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

Joined: Jul 12, 2010
Posts: 103
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

Joined: Jun 07, 2013
Posts: 19

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

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Final class can't be used on left side of instanceof operator ?/