Recently, I stumbled upon the following java syntax:
ArrayList<String> nodes = new ArrayList<String>(){{add("n1");add("n2");}};
At first, I thought that it is a syntax error, but to my surprise, the code gave no compilation or runtime error.
I have the following questions:
- Is there a standard definition and documentation for such declaration in Java?
- What happens when this code is compiled?
Please point me towards relevant literature.