|
|
|
|
|
by rld
4262 days ago
|
|
No, it applies for local variables as well: http://stackoverflow.com/questions/7423028/java-local-variab... 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? |
|
> 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?
It's an extra keyword, an extra complication in the language – one more binary choice to multiply with all the other options. It would be nice to get rid of the distinction altogether.