0

Possible Duplicate:
Why would one mark local variables and method parameters as “final” in Java?

I used PMD in my code and it always tells me to make method local variables final. Can someone tell me how this effects the general performance apart from making the code more readable.

Community
  • 1
  • 1
Madz
  • 1,273
  • 2
  • 18
  • 35

2 Answers2

1

There's no effect on performance and it's debatable whether it's more readable. Java should have made variables final by default.

blank
  • 17,852
  • 20
  • 105
  • 159
1

The biggest value of final is that it prevents programming errors. Regarding performance, I'd think the compiler can figure out the last write to a variable in most cases and do the necessary optimizations.

oksayt
  • 4,333
  • 1
  • 22
  • 41