In Java 10 Local-Variable Type Inference was introduced. It allows you to omit the expected type of
a variable by declaring it with the var
keyword.
While it is not always possible or cleaner to use this new way of declaring a variable, when the type on the left is the same as the one on the
right in an assignment, using the var
will result in a more concise code.
This rule reports an issue when the expected type of the variable is the same as the returned type of assigned expression.
MyClass myClass = new MyClass();
var myClass = new MyClass();