qualified-name

Why isn't a qualified static final variable allowed in a static initialization block?

佐手、 提交于 2019-11-26 04:45:47
问题 Case 1 class Program { static final int var; static { Program.var = 8; // Compilation error } public static void main(String[] args) { int i; i = Program.var; System.out.println(Program.var); } } Case 2 class Program { static final int var; static { var = 8; //OK } public static void main(String[] args) { System.out.println(Program.var); } } Why does Case 1 cause a compilation error? 回答1: The JLS holds the answer (note the bold statement): Similarly, every blank final variable must be