All variables in Java must be final
codemonkeyism.com
codemonkeyism.com
Maybe you should just use another language [..]
Believe me, I'm trying :) final ArrayList x = new ArrayList(); // x is final, so it can't be reassigned
x.add( "foo" ); // but we can still modify its contentshttp://java.sun.com/javase/6/docs/api/java/util/Collections....
For this reason we enforce that all object member fields must be final if possible, but we don't enforce it for local variables or method parameters. There are benefits to be had by doing that as well but IMO the benefit outweighs the return (and our IDE, IntelliJ, warns us if we reuse a local variable or method parameter).
SCNR...
Seriously, though, I've come to think of Java as "fear driven development".
ex, in class definition:
final int foo;
In constructor: try {
foo = 1;
} catch ( Exception e ) {
foo = 2;
} foo = try { 1 } catch(Exception e) { 2 }
much like the foo = bool ? 1 : 2 ternary if statement, versus the if() {} else {} clauses. def val = {try { 1 } catch(ex) { 2 }}.call()
assert(1 == val)Signed, foldl