我有一些类似以下代码:
public class Foo {
private int x;
public Foo() {
}
public Foo(int x) {
try {
//do some initialisation stuff like:
this.x = x;
}
catch(Exception ge){
//call empty constructor not possible
//this();
//this.EMPTY();
//Foo();
}
}
public static final Foo EMPTY = new Foo();
}
我想知道是否可能实现像这样的东西(我知道调用另一个构造函数必须是构造函数中的第一条语句)。 我在这里搜寻过但没有找到类似的内容,这让我相信也许我应该在实例化方法中处理错误逻辑。