1

I don't understand this warning:

found raw type: javax.swing.DefaultListModel
missing type arguements for generic class javax.swing.DefaultListModel

Netbeans seems to indicate that more information can be found from alt-enter but nothing comes up. The type should be ?

enter image description here

code:

package net.bounceme.dur.nntp.swing;

import java.util.logging.Logger;
import javax.swing.DefaultListModel;

public class MessagesListModel extends DefaultListModel {
    private static final long serialVersionUID = 1L;
    private static final Logger LOG = Logger.getLogger(MessagesListModel.class.getName());

    @Override
    @SuppressWarnings("unchecked")
    public void addElement(Object element) {
        super.addElement(element);
    }

}
4

2 回答 2

1

DefaultListModel is a generic type from Java 7.

You should do DefaultListModel<ClassName> instead of DefaultListModel.

Generally, this is more safe, since you specify what you should and what you shouldn't insert to the list. So if you made mistake, the compiler will arise an error.

于 2013-03-30T12:00:28.097 回答
1

From Java 7 DefaultListModel is considered as Generic class. See DefaultListModel . And while extending it you are not providing generic type to the DefaultListModel that you are extending. That's why your IDE is warning you.
Either you could ignore this warning. or As alternative you provide some Type parameter to it like <Integer> <String> or anything.. for example.

public class MessagesListModel extends DefaultListModel<String>
于 2013-03-30T12:00:52.567 回答