String[] boxOptions = {"1","2","4","8","16","20","40","100","400"};
JComboBox box = new JComboBox(boxOptions);
I had these exact lines of code in my program before, and wasn't getting this error. I did a bit of searching and the results I found are going a bit over my head. Any ideas?
我之前在程序中有这些代码行,没有得到这个错误。我做了一些搜索,我发现的结果有点过头了。什么好主意吗?
The error is:
错误的是:
JComboBox is a raw type. References to generic type JComboBox<E> should be parameterized
2 个解决方案
#1
17
You can use:
您可以使用:
JComboBox<String> box = new JComboBox<>(boxOptions);
This happens because JComboBox
is now a generic class.
这是因为JComboBox现在是一个泛型类。
#2
6
As of Java 7, generics were introduced into JComboBox component. Maybe you were using Java6 before. You should add JComboBox<String>
to the second line there.
在Java 7中,泛型被引入到JComboBox组件中。也许你以前用过Java6。您应该将JComboBox
#1
17
You can use:
您可以使用:
JComboBox<String> box = new JComboBox<>(boxOptions);
This happens because JComboBox
is now a generic class.
这是因为JComboBox现在是一个泛型类。
#2
6
As of Java 7, generics were introduced into JComboBox component. Maybe you were using Java6 before. You should add JComboBox<String>
to the second line there.
在Java 7中,泛型被引入到JComboBox组件中。也许你以前用过Java6。您应该将JComboBox