62,615
社区成员
发帖
与我相关
我的任务
分享
class A {
private final int x = 100;
private final int y = initY(); // 当然,如果这个方法声明抛出异常(比如throws Exception),那只能放到构造函数
private final int z;
A() {
z = ....;
}
}
private static final int x = 100;
private static final int y = initY(); // 这里方法必须是static,同样如果碰到throws Exception也只能进static段
private static final int z;
static {
z = ....;
}
public class Config {
public static int GLOBAL_VALUE = 100;
}
public class Worker {
public void foo() {
int value = Config.GLOBAL_VALUE;
while (condition) {
// do something with value
}
}
}