class A {
private final int t1;
private final int t2;
public A(int c1, int c2) {
t1 = c1;
initT2(c2);
}
private void initT2 (int c2) {
try {
t2 = c2;
} catch (...) {}
}
}
Run Code Online (Sandbox Code Playgroud)
t1 被初始化但 t2 没有。Cannot assign a value to final variable 's3Client'是错误。
如果我initT2在构造函数内移动函数的主体,它就可以工作。从构造函数内部调用它时,为什么它不能在构造函数外部工作?
java ×1