【问题标题】:How to acces variable in outer class with same name as in the inner class [duplicate]如何访问与内部类同名的外部类中的变量[重复]
【发布时间】:2016-02-29 15:28:44
【问题描述】:

这个问题是针对 Java 的

这是一个例子:

     public class A {

        int thing = 1;

          public class B {

             int thing = 2;
             System.out.println("I want to print out thing from class A" +what goes here?);
          }
     }   

【问题讨论】:

    标签: java class this outer-join


    【解决方案1】:

    你可以通过A.this.thing访问A的变量

    【讨论】:

      【解决方案2】:

      使用A.this.thing 表示“这里发生了什么?”

      【讨论】:

        【解决方案3】:

        您使用类名和this 来限定变量:

        System.out.println("I want to print out thing from class A" + A.this.thing);
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2015-04-06
          • 2011-06-08
          • 2013-07-08
          • 1970-01-01
          • 2012-09-03
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多