[英]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
. 我需要从类
Foo
更改属性time_to_play
,但是在方法change_player()
内部进行此更改,即类Bar
。
I cannot declare class Bar
outside class Foo
, and make an 'extend', and call super. 我不能在类
Foo
之外声明类Bar
,并且做一个'extend',并调用super。 ..., because it'd break the OO in my case. ......,因为在我的情况下它打破了OO。
Also, I don't want to make time_to_play
a static variable, calling Foo.time_to_play
另外,我不想让
time_to_play
成为静态变量,调用Foo.time_to_play
How I can do this? 我怎么能这样做?
What you want is: 你想要的是:
void change_player() {
Foo.this.time_to_play = // something
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.