class test
{
public static myclass x;
test() {
try {
x=new myclass();
//x is not null here
} catch(Exception e) {/*stuff*/}
//not null here
}
//x is null here in any other member method
}
请解释此行为的原因? 构造函数块结束后,是不是需要保留一个值而不是丢失它的构造函数?构造函数后的空值
这很难说发生了什么,没有看到更多的代码。你能告诉我们如何以及从哪里访问'x'? –
我很抱歉通过移动设备进出口。但其他类是一个普通的简单类抛出异常每种方法 –
我试图访问x在所有使用x == null的注释的地方如果语句 –