将阴影作为一个概念并没有什么神奇的。很简单,对名称的引用将始终引用最近的封闭范围内的实例。在您的示例中:
public class A { static final long tooth#1 = 1L; static long tooth#2(long tooth#3){ System.out.println(++tooth#3); return ++tooth#3; } public static void main(String args[]){ System.out.println(tooth#1); final long tooth#4 = 2L; new A().tooth#2(tooth#4); System.out.println(tooth#4);}}
我已经用数字以“ tooth#N”的形式注释了每个实例。基本上,任何在其他地方已经定义的名称的引入都会使该范围的其余部分的先前定义黯然失色。



