found raw type, missing return arguments for generic class

和自甴很熟 提交于 2019-12-24 15:11:58

问题


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 ?

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);
    }

}

回答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.




回答2:


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>


来源:https://stackoverflow.com/questions/15718217/found-raw-type-missing-return-arguments-for-generic-class

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