小编典典

JComboBox是原始类型。对通用类型JComboBox的引用 应该参数化

java

String[] boxOptions = {"1","2","4","8","16","20","40","100","400"};
JComboBox box = new JComboBox(boxOptions);

我之前在程序中有这些确切的代码行,但没有收到此错误。我做了一些搜索,发现的结果使我有些头疼。有任何想法吗?

错误是:

JComboBox is a raw type. References to generic type JComboBox<E> should be parameterized

阅读 713

收藏
2020-12-03

共1个答案

小编典典

您可以使用:

JComboBox<String> box = new JComboBox<>(boxOptions);

发生这种情况是因为JComboBox现在是泛型类。

2020-12-03