Re: inline methods
"G. Ralph Kuntz, MD" <grk@usa.net> wrote in message
news:1160055537.325744.107710@i42g2000cwa.googlegroups.com...
According to the Java language specification, a method can only be
"inlined" by the compiler if it is declared final (necessary, but not
complete requirement).
If I declare a class to be final, this implies that all of the methods
are final. Will javac inline the methods (if other conditions are met)?
http://java.sun.com/docs/books/jls/third_edition/html/classes.html#14844
<quote>
A private method and all methods declared immediately within a final class
(?8.1.1.2) behave as if they are final, since it is impossible to override
them.
</quote>
That said, your statement may be a bit misleading. javac will inline
methods only very rarely:
<quote>
Such inlining cannot be done at compile time unless it can be guaranteed
that Test and Point will always be recompiled together, so that whenever
Point-and specifically its move method-changes, the code for Test.main will
also be updated.
</quote>
The much more common case will be the JVM, and not javac, doing the
inlining.
<quote>
At run time, a machine-code generator or optimizer can "inline" the body of
a final method, replacing an invocation of the method with the code in its
body.
</quote>
- Oliver