LendKey

Wednesday, December 24, 2008

Why do we do final in Java?

Noticed lots of nice opensource code and Java style checker suggested to use final and static as much as possible.
I kinda understand why to use static, especially for methods, but not sure why final will help.
After a bit of google, I found the following claim at:

http://www.javaperformancetuning.com/tips/final.shtml#REF1

From: http://www.protomatter.com/nate/java-optimization/
Various tips. (Page last updated 1999?, Added 2000-10-23, Author Nate Sammons, Publisher Sammons). Tips:

Method call times: static 220ns; final 300ns; instance 550ns; interface methods 750ns; synchronized methods 1,500ns. [But times vary enormously depending on the VM and context].
Use static final methods where possible. [And do functional programming too ;-)]


Since the note was added around 1999 and 2000, I'm wondering it still stand true or not.

Now matter what, I will try my best to apply this policy to my code. But if anyone can explain why to me, it will make me feel much better.

Thanks!