我理解构造函数链是从最小的构造函数到最大的构造函数。例如
public MyChaining(){
System.out.println("In default constructor...");
}
public MyChaining(int i){
this();
System.out.println("In single parameter constructor...");
}
public MyChaining(int i,int j){
this(j);
System.out.println("In double parameter constructor...");
}
我理解到调用
this()
和 super()
的语句必须在第一行。但是是否有可能(如果可以的话,是否有效)绕过这个限制,从而链接不同的构造函数呢?例如,我有这两个共享一些代码的构造函数。
public Location(String _Name) throws IOException, JSONException {
//Three lines of unique code (must be executed before the shared code)
//Shared code
}
public Location(JSONObject json) {
//Shared code
}
第一个构造函数是否有可能调用第二个构造函数?