Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

This is not straight forward question. In my case the outer class variable and the inner class setter method's argument name is same. like:

class Problem {
    String s;
    int p;
    class Inner {
        String testMethod() {
         return  s = "Set from Inner";
        }
        void setP(int p)
        {
            p=p;  //it will do self assignment
        }
    }


}

now I cant initialize outer class instance variable p with this.p=p as it indicates the inner class. again I cannot do Problem.p=p; it gets an error. Now how can I assign outer p, keeping the inner Class method setP(int p)'s argument the same name p ?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
280 views
Welcome To Ask or Share your Answers For Others

1 Answer

This is how you can/should do it:

Problem.this.p

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...