关于 "this" 用法
About "this" usage
我正在学习Java
语言。
在研究关键字this
的时候,我想知道是否可以将其他对象分配给this
。
例如,如果我创建一个方法,它的参数是一个对象,我可以使用 this
关键字使当前对象引用参数对象吗?
不,你不能。在某种意义上 this
是隐含的 final
: 即 它不能更改为引用不同的对象。
此外,您不能偏离语言对 this
的定义。这是一个关键字,因此不能用于任何其他用途。
你不能,这是一个 Java 关键字。
查看所有关键字的 oracle site。
Here is a list of keywords in the Java programming language. You cannot use any of the following as identifiers in your programs. The keywords const and goto are reserved, even though they are not currently used. true, false, and null might seem like keywords, but they are actually literals; you cannot use them as identifiers in your programs.
Java中的this
关键字很像英语中的I
词。想象一下,你可以将 this
指向不同的对象,就像你不能用“我穿着一件蓝色衬衫”来暗示任何人的颜色一样,这显然是疯狂的衬衫比你自己的。
我正在学习Java
语言。
在研究关键字this
的时候,我想知道是否可以将其他对象分配给this
。
例如,如果我创建一个方法,它的参数是一个对象,我可以使用 this
关键字使当前对象引用参数对象吗?
不,你不能。在某种意义上 this
是隐含的 final
: 即 它不能更改为引用不同的对象。
此外,您不能偏离语言对 this
的定义。这是一个关键字,因此不能用于任何其他用途。
你不能,这是一个 Java 关键字。
查看所有关键字的 oracle site。
Here is a list of keywords in the Java programming language. You cannot use any of the following as identifiers in your programs. The keywords const and goto are reserved, even though they are not currently used. true, false, and null might seem like keywords, but they are actually literals; you cannot use them as identifiers in your programs.
Java中的this
关键字很像英语中的I
词。想象一下,你可以将 this
指向不同的对象,就像你不能用“我穿着一件蓝色衬衫”来暗示任何人的颜色一样,这显然是疯狂的衬衫比你自己的。