不兼容的类型:推理变量 E 具有不兼容的边界:无法初始化选择框



我不明白为什么当我尝试初始化ChoiceBoxes时这不起作用。

@FXML
private ChoiceBox<?> humanChoiceB;
String[] numbers = new String[]{"0", "1", "2", "3", "4", "5", "6", "7"};
humanChoiceB.setItems(FXCollections.observableArrayList(numbers));

当我编译时,出现了所述的错误:

incompatible types: inference variable E has incompatible bounds
equality constraints: capture#1 of ?
lower bounds: java.lang.String

奇怪的是,同一段代码适用于我的一个 NetBeans 本机项目,但不适用于我当前的 Maven 项目(也适用于 NetBeans IDE,或者说 NetBeans Maven)。

时间紧迫。非常感谢您的帮助。

您的声明

@FXML
private ChoiceBox<?> humanChoiceB;

应该是

@FXML
private ChoiceBox<String> humanChoiceB;

最新更新