简体   繁体   中英

Inner class modifying owning class's 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_play from class Foo , but make this change from inside the method change_player() , that is under class Bar .

I cannot declare class Bar outside class Foo , and make an 'extend', and call super. ..., because it'd break the OO in my case.

Also, I don't want to make time_to_play a static variable, calling Foo.time_to_play

How I can do this?

What you want is:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM