Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why are local variables not declared final in most open source java projects?

If I look at the java source source code in the OpenJDK or Hibernate or Apache I have yet to see any local variables declared final.

This suggests that the developers of some of the most widely used java software libraries:

  • do not believe the final keyword improves readablity.

  • do not believe it significantly improves performance.

Why do the majority of contrbuters on stackoverflow believe it it should be used (based on the highest voted responses)?

like image 880
user695654 Avatar asked Apr 06 '11 21:04

user695654


2 Answers

Probably because it's a hassle to type in the five LONG letters in the word final... why would they go through the pain of writing

final int x;

when it's twice as much typing as

int x;

?

We developers are lazy, you know... :P

like image 108
user541686 Avatar answered Sep 28 '22 07:09

user541686


do not believe the final keyword improves readablity.

Some people (such as myself) find excessive finals decreases readability.

do not believe it significantly improves performance.

final local variables does not improve performance.

like image 26
Steve Kuo Avatar answered Sep 28 '22 06:09

Steve Kuo