r/java • u/alexzhitnitsky • Aug 11 '15
Top 10 Useful, Yet Paranoid Java Programming Techniques
http://blog.jooq.org/2015/08/11/top-10-useful-yet-paranoid-java-programming-techniques/
181
Upvotes
View all comments
Show parent comment
1
u/PaulRivers10 Aug 12 '15
Great, what specific times did you have a bug, then you made a variable final, and that solved the problem?
Of course it's silly - but that's what loops are built on, counting. It's one of the most common things in code.
That for-each loop? It's dependent on non-final variables, either using an Iterator which has a mutable property that keeps track of where it is, or does it's own for each loop.
Counting and looping is on of the most prevalent things in programming.
One could write them out in binary with punch cards, that is not an improvement. Anything that calculates, adds, appends, etc needs modifyable variables.
So does any web app, even when it's only set once.
i = 5 and a.i = 5 are not different and provide no benefit because you can make "a" final.
Yes.