Came across this peculiar way of initializing Java maps inline.
The following code seems to be extending the Hashmap class using an anonymous class and is then using the (non static) initializer block.
Map<String, String> aMap = new HashMap<String, String>()
{{
put("gloves", "hand");
put("hat", "head");
put("shoes", "feet");
put("scarf", "neck");
}};
What are the performance implication of using the above code to initialize hashmaps inline?
I have not seen this being used very often. Is it considered to be a good java practice ?