Java - 'this' 运算符

use*_*246 1 java this operator-keyword

我对 Java 中的 this 运算符有疑问。如果程序员会编写这样的代码:

private int counter;

public Incrementor(int counter){
this.counter = counter;
}
Run Code Online (Sandbox Code Playgroud)

避免阴影效果并使用这个会更好吗:

private int counter;

public Incrementor(int startValue){
counter = startValue;
}
Run Code Online (Sandbox Code Playgroud)

this 运算符不会在未来的编程执行中使 this 运算符过时吗?

Mig*_*Prz 5

“this”关键字非常有用。你的例子很清楚,但想象一下你必须将自引用传递给外部对象的另一个方法的情况。