2023-05-03 11:06:20 +02:00
== Why is this an issue?
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 18:08:03 +02:00
2023-05-03 11:06:20 +02:00
=== Noncompliant code example
2021-04-28 16:49:39 +02:00
2022-02-04 17:28:24 +01:00
[source,java]
2021-04-28 16:49:39 +02:00
----
public class MyClass {
public enum COLOR {
RED, GREEN, BLUE, ORANGE;
}
public void mapMood() {
Map<COLOR, String> moodMap = new HashMap<COLOR, String> ();
}
}
----
2021-04-28 18:08:03 +02:00
2023-05-03 11:06:20 +02:00
=== Compliant solution
2021-04-28 16:49:39 +02:00
2022-02-04 17:28:24 +01:00
[source,java]
2021-04-28 16:49:39 +02:00
----
public class MyClass {
public enum COLOR {
RED, GREEN, BLUE, ORANGE;
}
public void mapMood() {
EnumMap<COLOR, String> moodMap = new EnumMap<> (COLOR.class);
}
}
----
2021-04-28 18:08:03 +02:00
2021-09-20 15:38:42 +02:00
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
include::message.adoc[]
endif::env-github,rspecator-view[]