>----- Oorspronkelijk bericht -----
>Van: Max Berger [mailto:[EMAIL PROTECTED]
>Verzonden: vrijdag, juni 13, 2008 01:11 PM
>> +1
>> I must say, I’ve never really grasped the benefit of doing this. I’d be
>> happy to be enlightened, though.
>Declaring a parameter / variable as final makes it immutable in the
>method where it is used. This is:

Come to think of it, I've always found it /very/ tricky to use the word 
'immutable' in case of objects, especially collections.

Declaring a method parameter or a member as final prevents only reassignment, 
but the assigned instance itself definitely remains mutable, unless additional 
precautions are taken to prevent structural modification after the assignment.

Doing this for each and every method seems to be a bit over the top. Especially 
if the method body is relatively short.
Anyway, I don't think there are any devs in the team at the moment who are in 
the habit of reassigning parameters (the fact that Vincent did not immediately 
see the benefit of that rule is a nice demonstration).
I look at it this way: it's much worse practice to reassign parameters 
(especially in public methods) than it is not to declare the parameters final. 
In that sense, I think the behavior in a language like PL/SQL (with roots in 
Ada) is much better defined: disallow any parameters from being reassigned, 
unless the programmer explicitly declares the parameter as such (OUT or IN 
OUT). Maybe an idea for Java 8. ;-)



Reply via email to