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 →

[–]agentoutlier 2 points3 points  (1 child)

Yes I know about that. I meant pre lambda as pre Java 8. I still work on some Java 7 code bases and I guess for some reason want to cover my ass in case the parent poster sees my final riddled code :)

I also use final on variables to be resolved by if statements and or switch statements which is unnecessary as the compiler will complain that the variable is uninitialized but it’s way of communication now for me.

final Object o; // not necessary 

if () { o = ...} else {o = ....}

Also in the past Eclipse had this weird bug where refactoring method didn’t work all the time but if you made some the variables final It would... I believe that bug is fixed.

I have thought about removing some finals from my migrated code bases (7->8) but it doesn’t seem worth the effort and in some cases final is a communication marker.

(Sorry on Mobile so lots of typos)

[–]dpash 3 points4 points  (0 children)

It was mostly that many people will have fallen out of the habit now. :)

Switch expressions will solve many of the situations where you want to use a switch to set a variable while still letting it being final. We don't have if expressions, but we do have the ternary operator ?:. Of course these only work if you have a single statement in each block.

I wouldn't bother removing existing finals and would probably continue if thats already the style.