Re:More Dirty Coding Tricks from Game Developers (2010)
by AdieuToLogic on Monday August 03, 2015 @02:41AM
(#9994154)
> `final` doesn't buy you as much in Java as `const` does in C, or (the lack of) `mut` in Rust.
Quite true.
> `final` only helps you avoid dumb reassignment bugs that tests should probably catch anyway ...
There is another reason for declaring parameters `final` in Java. It is the only way[1] which they can be used in an anonymous class definition such as:
return new SomeClass () {
override int addOne () {
return aNamedOuterMethodParam + 1;
}
}
1 - "The only way" as of Java 7. Newer versions may have removed this restriction, I haven't bothered to check.
Quite true.
> `final` only helps you avoid dumb reassignment bugs that tests should probably catch anyway ...
There is another reason for declaring parameters `final` in Java. It is the only way[1] which they can be used in an anonymous class definition such as:
1 - "The only way" as of Java 7. Newer versions may have removed this restriction, I haven't bothered to check.