0

From the code I wrote myself, and many others wrote, I can see that 'final' can be added to many method arguments, because those arguments passed in don't receive new values in the method body. However, in reality I rarely use 'final' in method arguments and see many (probably most) other people don't use it either.

Is there a good practice that I should follow here?

user697911
  • 10,043
  • 25
  • 95
  • 169
  • @Jason the accepted answer isn't valid anymore with Java 8 – Aaron May 24 '17 at 22:11
  • 3
    @Aaron - doesn't matter. It's still better for you to go and answer that other question, than to answer this one. That way, the answers (good, bad and indifferent) are all in one place. You can even comment on the accepted answer there that it's become invalid. – Dawood ibn Kareem May 24 '17 at 22:15
  • *"Is there a good practice that I should follow here?"* - Yea. Good practice is to *understand* what `final` achieves and .... make up your own mind, instead of delegating the *decision making* to someone else :-) – Stephen C May 24 '17 at 22:51
  • For what it is worth - adding `final` is a trade-off between (+) preventing accidental assignment to arguments, and (-) verbosity. There is no "one size fits all" correct approach. – Stephen C May 24 '17 at 22:55

0 Answers0