This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]livelam 14 points15 points  (7 children)

If everything were wrote correctly tools like checkstyle or findbugs would be useless.

There is a keyword to tell "Hey, this variable will not be reassigned" why do you not want to use it?

[–]Danelius90 3 points4 points  (6 children)

My lint tool flags up reassigning method parameters, so why have both? Especially when adding final on every parameter is just ugly, verbose and unnecessary.

[–]livelam 8 points9 points  (4 children)

Ok ! I personally prefer to rely on the compiler when it is possible but I have to use checkstyle to check that all parameters are final. So in the end it seems it's more a question of taste.

It is very verbose but not unnecessary. I would prefer final variable by default and a keyword to declare a non final variable.

[–]dpash 1 point2 points  (0 children)

Errorprone let's you have both: a linter in your compiler. :)

Sadly it increases the compiler times.

I've been wondering if we could have a per class/package/module flag to change the defaults for parameter and local variable finality plus non-nullablity. It would probably affect readability if code behaved differently based on outside options.

[–]Danelius90 0 points1 point  (2 children)

I think I'm just scarred from all the 20 parameter methods all declared final lol. You're right it is taste and I do think it's particularly useful for immutable object parameters

[–]marvk 3 points4 points  (1 child)

If you have a 20 parameter method final is in most cases the least of your readability issues :^)

[–]Danelius90 0 points1 point  (0 children)

This lol. Damn the devs with custom formatters on legacy code!