rspec/rules/S2293/rule.adoc

22 lines
748 B
Plaintext
Raw Normal View History

2021-01-27 13:42:22 +01:00
Java 7 introduced the diamond operator (``++<>++``) to reduce the verbosity of generics code. For instance, instead of having to declare a ``++List++``'s type in both its declaration and its constructor, you can now simplify the constructor declaration with ``++<>++``, and the compiler will infer the type.
2020-06-30 12:48:07 +02:00
2021-02-02 15:02:10 +01:00
2021-01-27 13:42:22 +01:00
*Note* that this rule is automatically disabled when the project's ``++sonar.java.source++`` is lower than ``++7++``.
2020-06-30 12:48:07 +02:00
== Noncompliant Code Example
----
List<String> strings = new ArrayList<String>(); // Noncompliant
Map<String,List<Integer>> map = new HashMap<String,List<Integer>>(); // Noncompliant
----
== Compliant Solution
----
List<String> strings = new ArrayList<>();
Map<String,List<Integer>> map = new HashMap<>();
----