时机1:直接赋值
public class Test {
static final double PI = 3.14159265;
}
时机2:静态代码块
public class Test {
static final double PI;
static {
PI = 3.14159265;
}
}
除了以上两个时机为static final赋值外,无其他办法。编译器也会报错“Variable 'PI' might not have been initialized.”