Jean said:
I see one case where people do indeed often not use final and
I never understood why : in method parameters.
I asked some java guru at work why most people, including himself,
would simply not declare method parameters final and the answer
was actually very vague.
I see three reasons that I think are quite plausible:
1. The same as anything else; it requires a certain amount of
sophistication to realize that final is a good thing; and by that time,
habits have a hold.
2. As mentioned in this thread, it should be universal, which means your
code would be much longer for no good reason. You should just be able
to assume that parameters are not assigned, and have a tool check it for
you.
3. The one no one has mentioned:
This contradicts what was apparently the intent of the language designer
who added syntax for final parameters. Historically, prior to Java 1.1,
final method parameters were illegal (probably mainly for reason 2
above). They were added in conjunction with inner classes
*specifically* so that there would be a legal way for a local inner
class to access the value of a parameter.
Because of this, it has become conventional to use final on parameters
to indicate that they will be accessed by a local inner class in this
way. That's clearly not the meaning of the word "final", but it's
strongly associated by the language rule.
Hence, ironically, using the "final" keyword to really mean "final"
could be very misleading, and could lead someone to assume that you
intend to access a parameter from a local inner class, when that's
really not the case.
I think the reason I see it as a poor practice is a combination of all
three factors, with emphasis on 2 and 3.
--
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.
Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation