一尘不染

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

阅读 512

收藏
2020-12-03

共1个答案

一尘不染

您可以使用:

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

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

2020-12-03