rspec/rules/S6212/java/rule.adoc

27 lines
771 B
Plaintext
Raw Normal View History

2021-04-28 16:49:39 +02:00
In Java 10 https://openjdk.java.net/jeps/286[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.
2021-04-28 16:49:39 +02:00
== Noncompliant Code Example
----
MyClass myClass = new MyClass();
----
2021-04-28 16:49:39 +02:00
== Compliant Solution
----
var myClass = new MyClass();
----
2021-04-28 16:49:39 +02:00
== See
* https://openjdk.java.net/jeps/286[JEP 286: Local-Variable Type Inference]