Final (Java): Difference between revisions

Content deleted Content added
fixing cites
rescuing dead link
Line 40:
</syntaxhighlight>
 
A common misconception is that declaring a method as <code>final</code> improves efficiency by allowing the compiler to directly insert the method wherever it is called (see [[inline expansion]]). Because the method is loaded at [[run time (program lifecycle phase)|runtime]], compilers are unable to do this. Only the runtime environment and [[Just-in-time compilation|JIT]] compiler know exactly which classes have been loaded, and so only they are able to make decisions about when to inline, whether or not the method is final.<ref>{{Cite web |title=IBMJava Developertheory and practice: Is that your final answer? |url=httpshttp://developerwww.ibm.com/languagesdeveloperworks/java/library/j-jtp1029.html |url-status=dead |archive-url=https://web.archive.org/web/20090208100217/http://www.ibm.com/developerworks/java/library/j-jtp1029.html |archive-date=2009-02-08 |access-date=2024-04-25 |website=developer.ibm.com}}</ref>
 
Machine code compilers that generate directly executable, platform-specific [[machine code]], are an exception. When using [[static linking]], the compiler can safely assume that methods and variables computable at [[compile-time]] may be inlined.