[英]Synchronized block in java
I came across the code: 我碰到了代码:
synchronized(Account.this)
{}
where Account
is a class. 其中
Account
是一类。
Does Account.this
mean any current instance of class Account? Account.this
是否表示Account类的任何当前实例?
This would probably be from an inner class of Account. 这可能来自Account的内部类。
class Account {
class InnerAccount {
...
synchronized(Account.this) {
}
}
}
Normally it is used inside of an inner class: It means the this
instance of the outer Account
class. 通常,它在内部类内部使用:这表示外部
Account
类的this
实例。
Writing this
by itself will return the instance of the inner class, not the outer class. 单独编写
this
将返回内部类的实例,而不是外部类的实例。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.