Java JComboBox 是原始类型。对泛型类型 JComboBox<E> 的引用应该被参数化
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20596020/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
JComboBox is a raw type. References to generic type JComboBox<E> should be parameterized
提问by tssguy123
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
采纳答案by BobTheBuilder
You can use:
您可以使用:
JComboBox<String> box = new JComboBox<>(boxOptions);
This happens because JComboBox
is now a generic class.
发生这种情况是因为JComboBox
现在是一个泛型类。
回答by britulin
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<String>
那里添加到第二行。