I'm not sure where the final keyword comes in handy when used on method arguments.
If we ignore the use of anonymous classes, readability, and intent statement, it appears nearly worthless to me.
public void testNullify() { Collection<Integer> c = new ArrayList<Integer>(); nullify(c); assertNotNull(c); final Collection<Integer> c1 = c; assertTrue(c1.equals(c)); change(c); assertTrue(c1.equals(c)); } private void change(Collection<Integer> c) { c = new ArrayList<Integer>(); } public void nullify(Collection<?> t) { t = null; }
Enforcing the consistency of some data is not as robust as it appears.
If the parameter is a primitive, it has no effect because it is supplied to the method as a value and modifying it has no effect beyond the scope.
If we pass a parameter by reference, the reference is a local variable, and changing the reference from within the method, as described in the scaler topic, has no effect outside of the method scope.
Consider the following simple test example. This test passes despite the fact that the method changes the value of the reference passed to it, which has no effect.