Tag: 影子

访问本地类中的shadowed变量

我是java的新手,我在下面的例子中感到困惑 public class Test { int testOne(){ //member method int x=5; class inTest // local class in member method { void inTestOne(int x){ System.out.print(“x is “+x); // System.out.print(“this.x is “+this.x); } } inTest ins=new inTest(); // create an instance of inTest local class (inner class) ins.inTestOne(10); return 0; } public static void main(String[] args) { […]

阴影的概念

给出以下代码: public class A { static final long tooth = 1L; static long tooth(long tooth){ System.out.println(++tooth); return ++tooth; } public static void main(String args[]){ System.out.println(tooth); final long tooth = 2L; new A().tooth(tooth); System.out.println(tooth); } } 你能解释一下影子的概念吗? 另外,主方法的代码中实际使用了什么tooth ? 我知道这是一个非常难看的代码,但丑陋是SCJP书籍作者的标准选择。