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