Local database reading edition

Is it necessary to declare a private method final?

Reconstructed from database records, not a captured original forum layout. Dates and display names are retained as recorded; timezone and real-world identity are not inferred. Historical advice, contact details and offers are not current. Original markup is shown as inert text.

Forum index · Java - Tips Of The Day

Opening post

Asha · 2001-02-16 14:07:12

In Today's tip i can discuss &quot;Where can i really improve the performance using &quot;final&quot; keyword,can i in private methods? I have seen most of the java performance articles suggest us to declare methods as final to increase the performance or the way you can optimize your code. The main points i can think of is<ul> <li>private methods cannot be overridden by subclasses </li> <li>final methods cannot be overridden by subclasses </li> <li>final methods allow for faster code when compiled with optimizations on (javac -O) </li> </ul> Why not declare all private methods as final? Subclasses may not override private methods by design. Furthermore, the final keyword tells the compiler that subclasses may not override a method regardless of its access level. Since private already implies that a subclass may not override a method, declaring a private method to be final is redundant. Making the declaration won't cause problems, but it won't accomplish anything either, since privates are automatically considered final. So the answer is, there is no need to declare private methods as final. Do most compilers treat private methods as final? yes, all compilers will treat private methods as final. Please note my discussion only applies to methods not members(Private final member variables are treated differently ) Asha Balasubramanyan http://www.ammu.org

Source notes

MyCommunity/nandighosha.org.zip!/forum/tools/snitz_forums_2000.mdb
Table: FORUM_TOPICS + FORUM_REPLY · record IDs: 41