Inner class that modifies the owner class attribute

I have a code like this:

class Foo() {
    time_to_play = 0
    class Bar() {
        void change_player() {
            //I need something HERE
        }
    }

}

And I need to change the attribute time_to_playfrom the class Foo, but make this change from the method change_player()that is under the class Bar.

I cannot declare a class Baroutside the class Fooand make an “extension” and call super .... because it broke OO in my case.

Also, I don't want the static variable to time_to_playcallFoo.time_to_play

How can i do this?

+3
source share
1 answer

What would you like:

void change_player() {
    Foo.this.time_to_play = // something
}
+6
source

Source: https://habr.com/ru/post/1752643/


All Articles