|
|
|
|
|
by StefanKarpinski
4264 days ago
|
|
> At least in Java, non-final variables can't be used inside anonymous inner classes. Aren't those members/fields not variables? If so, then those are effectively global not local, so that's a completely different story – I'm talking strictly about local variables. > True immutability makes reasoning far easier than just referential immutability. Yep, immutable types and constant global bindings are great. |
|
I still don't understand why you consider having a compiler-enforced restriction on mutation worse than letting readers figure out what was the developer's intent.
In Java, the only "downside" is having to add "final" as a modifier, which is negligible.
In Scala, the alternative is to declare that variable as "var" instead of "val". When would you ever choose var over val if your object isn't supposed to mutate?