import java.util.HashMap;
import java.util.Map;
public class Test{
private static final Map<Integer, String> myMap = new HashMap<Integer, String>();
static {
myMap.put(1, "one");
myMap.put(2, "two");
}
private static final Map<Integer, String> myMap2 = new HashMap<Integer, String>(){
{
put(1, "one");
put(2, "two");
}
};
}
和
public class GsonTest {
{
System.out.println("log 1");
}
static {
System.out.println("Log 2");
}
public GsonTest() {
System.out.println("Log 3");
}
public static void main(String[] args) throws Exception {
System.out.println("Log 4");
GsonTest t1 = new GsonTest();
System.out.println("Log 5");
}
}
import java.util.HashMap;
import java.util.Map;
public class Test{
private static final Map<Integer, String> myMap = new HashMap<Integer, String>();
static {
myMap.put(1, "one");
myMap.put(2, "two");
}
private static final Map<Integer, String> myMap2 = new HashMap<Integer, String>(){
{
put(1, "one");
put(2, "two");
}
};
}