type JList does not take parameter type <String>

别等时光非礼了梦想. 提交于 2019-12-12 16:07:32

问题


When I try to compile some code I keep getting these errors:

CCC.java:21: type javax.swing.JList does not take parameters
JList<String> list;

or:

CCC.java:30: type javax.swing.DefaultListModel does not take parameters
DefaultListModel<String> jobs, DefaultListModel<String> closJ) throws HeadlessException {

I have about 26 of the same error when I try to remove the section i get about 150 lines of errors can anyone help please.


回答1:


Generics were added to JList in Java 7. Here's an example from the JList documentation:

String[] data = {"one", "two", "three", "four"};
JList<String> myList = new JList<String>(data);

Make sure you're using Java 7+.




回答2:


Assuming you are using Java 1.6

DefaultListModel is not generic class, you can't instantiate it with by passing concrete parameters, same for JList also.

Just change your code like:

JList list;

and

 DefaultListModel jobs


来源:https://stackoverflow.com/questions/12879342/type-jlist-does-not-take-parameter-type-string

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