是否有充分的理由使用阴影字段的参数?这两者有什么区别:
public class Point {
public int x = 0;
public int y = 0;
//constructor
public Point(int a, int b) {
x = a;
y = b;
}
}
和
public class Point {
public int x = 0;
public int y = 0;
//constructor
public Point(int x, int y) {
this.x = x;
this.y = y;
}
}
如果你this
在这个例子中使用不带参数的关键字会影响字段(我猜这只是不必要的):
public class Point {
public int x = 0;
public int y = 0;
//constructor
public Point(int a, int b) {
this.x = a;
this.y = b;
}
}