这是我的 Point 类:
public class Point
{
private int _x;
private int _y;
public Point(Point other)
{
_x = other._x;
_y = other._y;
}
}
在 Point 构造函数内,我需要做一些其他事情来避免别名,或者我所做的可以吗?
最佳答案
你的代码应该没问题。就我个人而言,为了清晰起见,我喜欢在构造函数中使用 this
,但这是一个风格问题:
public Point(Point other)
{
this._x = other._x;
this._y = other._y;
}
关于java - 构造函数内的别名 - 类 Point,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20280920/