We have a habit of constructing EnumMap<K,V>
instances like in the following EnumMapExample.java
example:
package test;
import java.util.EnumMap;
public class EnumMapExample {
enum TestEnum {SOME_VALUE, SOME_OTHER_VALUE}
private final EnumMap<TestEnum, String> myEnumMap = new EnumMap<TestEnum, String>(TestEnum.class) {
{
// How is this construct called?
put(TestEnum.SOME_VALUE, "someValue");
put(TestEnum.SOME_OTHER_VALUE, "someOtherValue");
}
};
public void printMyEnumMap() {
for (final TestEnum key : myEnumMap.keySet()) {
final String value = myEnumMap.get(key);
System.out.println("myEnumMap key: " + key + " has value " + value);
}
}
public static void main(final String[] args) {
new EnumMapExample().printMyEnumMap();
}
}
Likely a question with a quick answer, but I can't for the Google of me find how this way of filling the private final EnumMap<TestEnum, String> myEnumMap
with the 2 (contrived) enum types is called and how it works?
Question refinement: So I'm calling new EnumMap<K,V>(SomeEnum.class){{ /* initialization code */ }};
Note the double curly braces {{ }}
before the semicolon ;
. What's that double braces thing?