2 ms·
Curious. I haven't written anything in Java for a long time so I wasn't aware that you could mark parameters as `final`, or what that would mean. If you are wo
by shoo 11y ago
Curious. I haven't written anything in Java for a long time so I wasn't aware that you could mark parameters as `final`, or what that would mean.
If you are working with code where you know that functions never modify their parameters then it is simpler to reason about what it does. I prefer to write code this way myself if there is no language mechanism to enforce it.
Other possible uses of `final` (to tag methods or classes) have the downside of reducing the flexibility of code by removing interfaces / "seams" that can be overridden. This reduction of flexibility will generally make things harder to test, which may or may not matter. Michael Feathers has a short article discussing this [1].
[1] Michael Feathers' "Testable Java" : http://www.objectmentor.com/resources/articles/TestableJava.pdf http://www.objectmentor.com/resources/articles/TestableJava....