What is the use of using final keyword for local primitive variables in java. Is there any performance benefit ?
Asked
Active
Viewed 1,215 times
0
-
I don't think there is a performance benefit. Except you use a local variable or parameter inside an anonymous class defined inside a method (in this case you must define it final), it's no too useful. – Manuel Schmidt May 01 '17 at 09:01
1 Answers
2
The final keyword has more than one meaning:
- a final class cannot be extended
- a final method cannot be overridden
- final fields, parameters, and local variables cannot change their value once set
Using final:
- clearly communicates your intent.
- allows the compiler and virtual machine to perform minor optimizations
- clearly flags items which are simpler in behaviour - final says, "If you are looking for complexity, you won't find it here."

Jamal Alkelani
- 606
- 7
- 19