News on an old Java Wisdom

I am fully aware of the brace initialisation of anonymous classes, but I didn’t know that this can help to improve readability of Java programs until I read this nice post:

Map<Integer, String> map = new HashMap<Integer, String>() {{
 put(1, "one");
 put(2, "two");
 put(3, "three");
 put(4, "four");
 put(5, "five");

The author said that this could help in GUI programming:

JFrame frame = new JFrame() {{
   add(new JLabel("Hello, World!"));

Nice !