在java中使用“this”

using “this” in java

本问题已经有最佳答案,请猛点这里访问。

大家好,我对Java还很陌生。当涉及到实例变量时,我得到了"this"的概念,但是当我在没有参数的构造函数中使用它时,我会有点困惑。所以我的问题是像这样的东西是如何工作的?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
private double x;
private double y;

public static final double EPSILON = 1e-5;
public static boolean debug = false;


public Point(double x, double y){
    this.x=x;
    this.y=y;  // Done sets the x,y private types to the x,y type provided in the ()
}

public Point(){
    this(0.0,0.0);  //Sets, x and y to doubles of 0.0,0.0??
}                   //How does this work?

我的point()构造函数会通过调用point(x,y)构造函数来创建(0.0,0.0)的原点吗?任何有关这方面的澄清都会帮我很多忙!


(P)EDOCX1 4 is a special syntax only available inside constructors.What it does is call another constructors with the given arguments.So calling EDOCX1 plus 5 welcx1 will invoke the constructor EDOCX1 commercial 6 with the values EDOCX1 commercial 7.这,在图恩,将是塞特EDOCX1的英文字母8和EDOCX1(p)


(P)当呼叫EDOCX1的英文字母为0时,你将呼吁建筑商到另一个建筑商(在这种情况下,第一个建筑商)。So you create a EDOCX1 commency 1(0.0).(p)(P)You basically states that whenever one calls EDOCX1,welcome 2,it is replaced by Java with EDOCX1(p)(P)有时,它可能被用来制造机会(呼吁一个没有任何参数的建筑商)。In that case each constructor simply handles its additional parameters which is more origined to"separation of concerns".(p)(P)For instance:(p)字母名称


(P)Poine()will init x and with 0.0(p)(P)Point(Double X,Double Y)will init x and y with x and y in the params of the function.(p)(P)This in point(double X,double Y)was a point of the point class(p)(P)This in point(……)you can see as a constructor for the point class,it will(p)(P)Call Point(Double X,Double Y).(p)