This seems to be a little-known language skill. I see that most people initialize static constants in Java by
Copy the code code as follows:
public static final Map<String, String> DATA = new TreeMap<String, String>();
static
{
DATA.put("a", "A");
//blah blah blah
}
Use the static block of the class to initialize DATA. In fact, there is another way to write it:
Copy the code code as follows:
public static final Map<String, String> DATA = new TreeMap<String, String>()
{{
this.put("a", "A");
//blah blah blah
}};
This actually takes advantage of the characteristics of anonymous classes. The inner { is used as the constructor of the anonymous subclass, so the initialization code can be directly inserted. This little language trick is not common, but it is more practical.