可能重复:
如何处理引发检查异常的静态最终字段初始化程序
在此示例中,我收到错误The blank final field myClass may not have been initialized:
private final static MyClass myClass; // <-- error
static {
try {
myClass = new MyClass(); // <-- throws exception
myClass.init();
} catch (Exception e) {
// log
}
}
在该示例中,我收到错误The final field myClass may have been assigned:
private final static MyClass myClass;
static {
try {
myClass = new MyClass(); // <-- throws exception
myClass.init();
} catch (Exception e) {
myClass = null; // <-- error
// log
}
}
有解决这个问题的办法吗?