adam bien's blog

Final Method Parameters Should Generate Compiler Warnings... 📎

Another emerging trend in "Quality Assurance Driven Development" is the overuse of the "final" keyword. Especially the use as a method parameter:
 public void setCount(final long count) {
        this.count = count;
    }


comes with a little value. It could help you in cases when you forget "this", or try to assign something to a parameter. Both errors would be immediately visible in the first unit or integration test.

I forget sometimes the "this." keyword what immediately results in an IDE (NetBeans / IntelliJ in my case) warning. I cannot remember any case of an attempt to assign something to a parameter...

Defining final in every method declaration just increases the noise and prevents rather esoteric errors. Btw. final method parameters are sometimes absolutely required - and therefore compiler cannot warn you. The following codes does not compile without a final method parameter:

public void setCount(long count) { // final required here...
        this.count = count;
        new Runnable(){

            @Override
            public void run() {
                System.out.println("" + count);
            }
            
        };
    }

Did you ever had trouble with non-final method parameters?