Re: effects of "final" in parameters



Chris Uppal wrote:

Final /fields/ are different, as are final methods -- and it's the latter that
are sometimes touted as an optimisation (which I doubt, but have never tried to
measure).

Years ago making a method used in an inner loop final could improve performance significantly. I found it useful for one get method once, and then removed the field. However, this century JVMs will inline methods anyway and it makes no difference.

Final fields may have some impact on performance from Java 1.5. They need not be reread, even when dealing with synchronised blocks and reading volatiles. I haven't tested to see whether that actually makes any difference. If you have a field that could be made final, it should be made final regardless of performance concerns.

Tom Hawtin
--
Unemployed English Java programmer
http://jroller.com/page/tackline/
.