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

穿精又带淫゛_ 提交于 2020-01-30 20:14:33

问题


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

回答1:


You can use:

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

This happens because JComboBox is now a generic class.




回答2:


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.



来源:https://stackoverflow.com/questions/20596020/jcombobox-is-a-raw-type-references-to-generic-type-jcomboboxe-should-be-param

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!