不重复,这是一个语义问题?
哥伦比亚大学的一位教授说过,关键字 this
指向当前的类
( See Page 21 )。我 99% 确信这是不正确的。
我想说它传递给类实例
或对象
。有没有一种首选方式可以简洁地表达 this
所指向的内容。
谢谢,我只是希望我的笔记准确。
最佳答案
来自Oracle docs :
The keyword this may be used only in the body of an instance method, instance initializer, or constructor, or in the initializer of an instance variable of a class. If it appears anywhere else, a compile-time error occurs.
...
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.
来自wiki :
this
Used to represent an instance of the class in which it appears. this can be used to access class members and as a reference to the current instance. The this keyword is also used to forward a call from one constructor in a class to another constructor in the same class.
关于java - "this"指向什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19078171/