今天遇到遮蔽(shadowing)的问题,故翻开JLS看
但是这句话我始终没用读懂,自己的英语实在不咋地,没办法来这问一下
A declarations d of a type named n shadows the declarations of any other types named n that are in the scope 
at the point where d occurs throughout the scope of d.
纯英语问题,呵呵,想了好久也没读明白这句话

解决方案 »

  1.   

    四命名ñ阴影名为n的范围,在任何其他类型的声明一A型声明 
    在点这里d出现整个D.范围
      

  2.   

    在D的作用域范围内  n类型中的声明D遮蔽了所有n中的其他声明好比n是一个类 class1
    D是一个class1的方法
    而int i是D中的声明class1{
      int i =0;
      public void D(){
        int i = 1;
        System.out.println(i);
       }
    }// output: 1也就是说D遮蔽了类class1中的变量i其实LZ已经会了
      

  3.   

    原文是“A declaration d of a type named n shadows the declarations of any other types named n that are in scope at the point where d occurs throughout the scope of d.”,这里说的应该是java的类型遮蔽,而不是#3楼提到的变量遮蔽。我试着逐句解释一下:
    A declaration d of a type named n是说 声明了类型n的声明语句d;
    declarations of any other types named n 是说 其它声明了名为n的类型的声明语句;
    A declaration d of a type named n shadows the declarations of any other types named n 合起来就是“声明了类型n的声明语句会遮蔽其它声明了类型n的声明语句”,在哪儿遮蔽呢?看后面的定语从句:
    that are in scope at the point where d occurs throughout the scope of d,that就是指那些其它的声明类型n的声明语句,that are in scope 就是说这些被遮蔽的声明是处在一个范围内的,这个范围就是at the point where d occurs throughout the scope of d,既从声明开始直到d作用域结束。
    网上关于类型遮蔽的例子比较多,随手搜了一个:
    class String{
    }
    public final class main{
            public static void main(String[] args){
     
            }
    }
    这里的String就会遮蔽java.lang.String,当然这段代码通不过编译的。
      

  4.   

    呵呵,这样一看清楚多了,主要是that are in scope at the point 迷惑我,谢谢