As Sanjay T. Sharma clearly explained, it's creating anonymous class instance. In fact, it is extending java.util.HashMap
. Consider the following code:
package com.test;
import java.util.HashMap;
import java.util.Map;
public class Demo {
public static void main(String[] args) {
Map<String, String> mapSimple = new HashMap<String, String>();
System.out.println("Simple java.util.HashMap:");
System.out.println("\t" + mapSimple.getClass());
Map<String, String> map = new HashMap<String, String>() {
{
put("a", "b");
}
};
System.out.println("Anonymous class based on java.util.HashMap:");
System.out.println("\t" + map.getClass());
System.out.println("\t" + map.getClass().getSuperclass());
}
}
It produces the following output:
Simple java.util.HashMap:
class java.util.HashMap
Anonymous class based on java.util.HashMap:
class com.test.Demo$1
class java.util.HashMap
Pay attention to the name of such anonymous class, and that this class extends java.util.HashMap
.