Default inspection for "local variable is redundent".

I'm getthing this inspection lots in my code now, where I've got something like this:

final BasicAuthInfo userAuthInfo = new BasicAuthInfo(username, password);
return userAuthInfo;

Even though it really is redundent, I view this as good coding practice; It's slightly documentory because of the variable name, and its easier to set a breakpoint when debugging.

The compiler should optimize this anyone (same bytecode output). So does this inspection really deserve to be on by default?

1 comment

There's a flag available on the inspection which allows you to disable it for values that are immediately returned or thrown, for precisely the reasons you list. I can see arguments for not enabling the inspection by default, or for enabling that flag by default, but believe the current default settings are actually optimal in terms of maximizing the new user experience. It would take either really good arguments, or a JetBrains decree for me to change them.

--Dave Griffith


Please sign in to leave a comment.