views:

27

answers:

1

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?

+5  A: 

What you want is:

void change_player() {
    Foo.this.time_to_play = // something
}
jjnguy
Of course this is only needed in the case where the inner class has a field of the same name. Then again it's always good to be sure.
musiKk
@musikk yup, i like being explicit in my code though.
jjnguy