Block scope variables
问题 This will compile class X { public static void main(String args[]) { { int a = 2; } { int a = 3; } } } This won't class X { public static void main(String args[]) { int a = 2; { int a = 3; } } } I expected both to compile (maybe it is the way C works?). What is the reason because it is not possible to declare a variable in a block with the same name of one in the outer block? 回答1: The short answer is: Because this is the way the Java language is defined in JLS §6.4. You might be used from