Shaun Abram
Technology and Leadership Blog
Getting rid of IntelliJ warning: Local variable is redundant
When dealing with a piece of code like this
String id = "abc";
return id;
IntelliJ may give a warning message:
Local variable 'id' is redundant
I can see IntelliJ’s point. The code could be rewritten as follows:
return "abc";
However, sometimes it can be useful to use a variable name as a form of documentation.
Also, and more often, I don’t want to see this warning pop up for other people’s code! If they wish to use a “redundant” variable, who am I to argue? I certainly don’t want to be warned about it every time I do a commit.
To disable this warning, deselect the following:
Preferences -> Editor -> Inspections (-> Java) -> Data flow issues -> Redundant local variable -> Ignore immediately returned or thrown variables
Or you can setup custom handling for tests (e.g. weak warnings) under Severity by Scope.
(Based on IntelliJ 15)
Tags: intellij