package test;
import java.util.HashMap;
class Check {
private static Check check = new Check();
private static HashMap<String,String> map = new HashMap<String, String>();
static{
System.out.println("***********In static block***********");
Check.map.put("1", "One");
Check.map.put("2","Two");
}
private Check(){
System.out.println("Map Contains "+map.get("1"));
}
public static Check getCheck() {
return Check.check;
}
}
public class CheckStatic{
public static void main(String[] args) {
Check.getCheck();
}
}
我创建了具有静态块的 Singleton 类。在静态块中,我已经初始化了 hashmap 并尝试在 Singletion 类的构造函数中访问它。但是我得到了 exceptionInInitializerError。请建议正在尝试什么是错误的......