I need to statically initialize an EnumMap. I know two ways.
Using of() method of Map
private static final Map<<EnumKey>, <Value>> TEST_MAP = Map.of(ENUM_CONST1, "Value1", ENUM_CONST2, "Value2");
Using double brace initialization
private static final Map<<EnumKey>, <Value>> TEST_MAP = new EnumMap<>(EnumKey.class) { { put(ENUM_CONST1, "Value1"); put(ENUM_CONST2, "Value2"); } };
Is there any other cleaner and more efficient way?
EnumMap
, but aMap
(immutable one) – Annettaannette