Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
有人可以解释一下吗?并举一个简短而简单的例子。谢谢!
this是对当前对象的引用,并隐式传递给非静态方法。 this.x取消引用以获取“x”属性。
this
this.x
如果您想在函数参数和类成员之间消除歧义,请使用它。
public void setX(int x) { this.x= x; }
在这种情况下它是有效但多余的:
public void setX(int xValue) { this.x= xValue; }
或者简单地说:
public void setX(int xValue) { x= xValue; }