0

我是java编程的新手,我正在尝试将文件列表添加到一个粗糙的小型媒体播放器中。我正在使用 JList 来显示文件名字符串,但想将它们存储在 DefaultListModel 中,以便我可以添加和删除文件。就我而言,我需要为我的集合中的每个文件添加一个字符串(存储在不同的类中),但是每当我尝试编译时,都会出现以下错误:

[pathname]/classname.java 使用未经检查或不安全的操作。使用 Xlint 重新编译:详细信息未选中

有人可以告诉我我做错了什么吗?

private void makeList()
{
    DefaultListModel listModel = new DefaultListModel();
    int collectionSize = tracklist.getCollectionSize();

    for(int i = 0; i < collectionSize; i++){
        String filename = tracklist.getFilename(i);
        listModel.addElement(filename);
    }
}
4

1 回答 1

2

you need to declare listModel like this

DefaultListModel <String> listModel = new DefaultListModel<>();

This enforce the compiler to check if you add a real string object into this collection whose elements must be the string type

于 2014-01-14T04:34:09.083 回答