Introduction to FXMLには、<fx:root> を使用してカスタム コンポーネントを構築する方法の例があります。ドキュメントの一部を次に示します。
public CustomControl() {
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("custom_control.fxml"));
fxmlLoader.setRoot(this);
fxmlLoader.setController(this);
try {
fxmlLoader.load();
} catch (IOException exception) {
throw new RuntimeException(exception);
}
}
ここでは、コンストラクターが「this」をリークしており、不快な結果を引き起こす可能性があります。
コンストラクタで FXMLLoader に 'this' を渡しても安全ですか? そうでない場合、このコードを安全にするための提案はありますか?