我正在開發一個項目,我在想,是否將參數的順序傳遞給構造函數。例如,如果我創建了一個程序:構造函數排序
public class Test{
int t3;
String h;
Test(int t1, String t2){
t3 = t1;
String h = t2;
}
}
難道不管我,我這樣做:的
Test t4 = new Test("hello", 6);
代替
Test t4 = new Test(6, "hello");
喜歡在構造函數中的順序?謝謝!
試一下,看看會發生什麼。 – Kayaman
是的,它很重要。 –
在上面的例子中,第一個參數必須是一個整數,第二個參數必須是一個字符串。 –