gpt4 book ai didi

java - "this"指向什么?

转载 作者:行者123 更新时间:2023-12-02 03:59:13 26 4
gpt4 key购买 nike

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

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

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com