Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are final inner classes?

What does it means to declare a non-static inner class as final?

I have tried many links on google and stackoverflow.com as well but all of them seem to be dealing about inner classes accessing final members not final inner classes itself. I found this link on google but even it doesn't explains it.

Thanx in advance!

like image 225
Surender Thakran Avatar asked Jun 14 '12 05:06

Surender Thakran


People also ask

Can inner classes be final?

Local Inner classes are not a member of any enclosing classes. They belong to the block they are defined within, due to which local inner classes cannot have any access modifiers associated with them. However, they can be marked as final or abstract.

What is outer and inner class?

Writing a class within another is allowed in Java. The class written within is called the nested class, and the class that holds the inner class is called the outer class. Following is the syntax to write a nested class.


1 Answers

There is no semantic difference between making a top-level class final and making an inner class final: it tells the compiler that you cannot inherit from the class. Marking classes final is sometimes done to let the compiler skip a virtual table lookup, but this is often regarded as premature micro-optimization.

like image 87
Sergey Kalinichenko Avatar answered Oct 07 '22 03:10

Sergey Kalinichenko