问题
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