rspec/rules/S1640/java/rule.adoc

35 lines
655 B
Plaintext
Raw Normal View History

2021-04-28 16:49:39 +02:00
When all the keys of a Map are values from the same enum, the ``++Map++`` can be replaced with an ``++EnumMap++``, which can be much more efficient than other sets because the underlying data structure is a simple array.
2021-04-28 16:49:39 +02:00
== Noncompliant Code Example
----
public class MyClass {
public enum COLOR {
RED, GREEN, BLUE, ORANGE;
}
public void mapMood() {
Map<COLOR, String> moodMap = new HashMap<COLOR, String> ();
}
}
----
2021-04-28 16:49:39 +02:00
== Compliant Solution
----
public class MyClass {
public enum COLOR {
RED, GREEN, BLUE, ORANGE;
}
public void mapMood() {
EnumMap<COLOR, String> moodMap = new EnumMap<> (COLOR.class);
}
}
----