This question already has answers here:
What causes javac to issue the “uses unchecked or unsafe operations” warning

(12个答案)


在10个月前关闭。





    try{
        String[] mobileSuit;
        File packageFile = openDialogFile("Select", "Choose folder that contain overall mobile suit folder", JFileChooser.DIRECTORIES_ONLY);
        mobileSuit = packageFile.list();
        DefaultListModel<String> listModel = new DefaultListModel<>();
        for(String el : mobileSuit){
            listModel.addElement(el);
        }
        this.packagePath = packageFile.getPath();
        JList_mobileSuit.setModel(listModel);
        JList_mobileSuit.setSelectedIndex(0);
    }catch(java.lang.NullPointerException e){

    }


当我取消注释“ JList mobileSuit.setModel(listModel)”行时,netbeans的输出报告“ TestUI.java使用未经检查或不安全的操作。注意:使用-Xlint:unchecked进行重新编译以获取详细信息。”我仍然对我的内容感到困惑做错了请帮帮我

最佳答案

它应该是

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

而且JList也可以采用String
JList<String> JList_mobileSuit = new JList<>(listModel);//JList<String>(listModel);

09-27 11:47