java这个关键字 [英] java this keyword

查看:127
本文介绍了java这个关键字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经读过,在Java中你不必将 this 关键字显式绑定到object,它由解释器完成。它与Javascript相反,您始终必须知道的值。但是Java中的这个在哪里指向类或对象?或者它有变化吗?
这个问题是我尝试理解基本OO概念和设计模式的一部分,因此我可以将它们应用于Javascript。
谢谢。

I have read that in Java you don't have to explicitly bind the this keyword to object, it is done by interpreter. It is opposite to Javascript where you always have to know the value of this. But where is this in Java is pointing - to class or object ? Or does it vary ? This question is a part of my attempt to understand basic OO concepts and design patterns so I can apply them to Javascript. Thank you.

推荐答案

Java语言规范声明:


当用作主表达式时,关键字this表示值
,它是对实例方法为
调用的对象(第15.12节)或对正在构造的对象的引用。

When used as a primary expression, the keyword this denotes a value that is a reference to the object for which the instance method was invoked (§15.12), or to the object being constructed.

即它总是指向一个对象,而不是一个类。

I.e. it always points to an object, not a class.

这篇关于java这个关键字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆