Java - How to access Outer class field if the fields have same name

后端 未结 5 1983
长发绾君心
长发绾君心 2021-01-26 02:26

Consider the following code

class OuterClass{
    class InnerClass{
        int x;
        int y;
        void calculateX(){
            x = y+z;//I want to acce         


        
5条回答
  •  有刺的猬
    2021-01-26 03:12

    It generally shouldn't (it's a sign of a design problem), but try OuterClass.this.y.

提交回复
热议问题