“这个” java查询点
这里是一位休闲 Android 开发人员,我猜这只是一个简单的查询。
我想知道“this”在 java/Android 中到底意味着什么。有时您会将其视为某些方法的固有部分,但我很好奇它到底具体指的是什么。谢谢!
Recreational Android developer here, with what I would guess is a simple query.
I am wondering exactly what "this" means in java/Android. Occasionally you see it as an inherent part of some methods, but I am curious what, in detail, it really refers to. Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
在我看来,这是:
您可以在四个中使用它不同的上下文:
为了更好地理解您需要一些示例:
更多信息:
From my view this is:
You can use it in four different contexts:
To get better understanding you need some example:
More information:
this
用于引用当前类实例。请参阅 http://www.javabeat .net/qna/16-what-is-super-and-this-keyword-in-java/this
is used to refer to the current class instance. See http://www.javabeat.net/qna/16-what-is-super-and-this-keyword-in-java/当前对象
this 指的是在字段被隐藏时主要使用的
,例如:
this.x 指的是Example 类中x 的实例,而不是传递到方法中的x。
如果您想了解更多信息,我编辑添加了链接:
此关键字
this refers to the current object
used mostly when a field is shadowed
for example:
this.x is refering to the instance of x in the Example class not the x passed into the method.
I edited to add the link if you want to read more:
this keyword
它指的是调用该方法的类的实例。
例如,如果您有:
如果“moo()”方法在其定义中使用“this”,它将引用奶牛“buddy”。
It refers to the instance of the class on which the method was called.
For example, if you have:
If the "moo()" method uses "this" inside of its definition, it will refer to the Cow "buddy".