1 回答

TA貢獻1900條經驗 獲得超5個贊
Java 是一種傳值語言。對象類型變量不是對象指針,它們只是保存一個對象引用(即內存地址)。例子:
String str = "Hello"; // A String type variable holding reference of "Hello" string
String str2 = str; // Variable "str2" now copies the reference of "str"
String str2 = "World"; // Variable "str2" changes the reference it holds to the string "World" (in other word, it is being replaced)
它經常被混淆,因為以下是有效的:
List<String> foo = new ArrayList<>(); // Let foo hold the reference of an empty arraylist
List<String> bar = foo; // Let bar hold the reference that is held by foo
bar.add("hello");
System.out.println(foo); // Prints "[hello]"
這是有效的,因為bar已經復制了ArrayListfrom的對象引用foo,因此對ArrayListvia 的任何操作bar都將由 反映foo,因為它們都持有相同的對象引用。
回到你的問題。如果tacController尚未加載 FXML 文件,則所有Button引用都將為null. 所以你要做的是復制null引用并將這些null引用保存在數組中。因此,您將永遠無法訪問實際Button對象。
添加回答
舉報