java - "this"指向什么?

标签 java

不重复,这是一个语义问题?

哥伦比亚大学的一位教授说过,关键字 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/

相关文章:

java - 静态变量、libgdx 和 android 暂停/恢复内存使用

java - 如何使用免费工具查找类加载器泄漏?

java - SQS FIFO 使用 MessageGroupId 接收消息

java - Wicket 组件不会通过 AJAX 刷新

java - 如何有效地对多维数组进行排序

java - AbstractMethodError:org.apache.bval.jsr303.ConfigurationImpl 缺少方法 getDefaultParameterNameProvider() 的定义

java - LibGDX GDX-Pay 崩溃

java - 打印数字系列 1,n,2,n-1,3,n-2,... 的逻辑应该是 1 到 n(给定的输入)

java - 使用 iText : java. lang.OutOfMemoryError:请求的数组大小超出 VM 限制

java - 如何淡化 GWT FlexTable 中单元格的颜色