当我构建/运行由 NetBeans Applet Form 制作的小程序时,出现 2 个错误:
warning: [unchecked] unchecked call to DefaultComboBoxModel(E[]) as a member of the raw type DefaultComboBoxModel
levelBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "1", "2", "3", "4", "5", "6", "7" }));
where E is a type-variable:
E extends Object declared in class DefaultComboBoxModel
warning: [unchecked] unchecked call to setModel(ComboBoxModel<E>) as a member of the raw type JComboBox
levelBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "1", "2", "3", "4", "5", "6", "7" }));
where E is a type-variable:
E extends Object declared in class JComboBox
2 warnings
如果我点击下拉菜单,我会在它旁边看到一个感叹号。这是为什么?
此外,这与“-Xlint:unchecked”选项有关。
最佳答案
new javax.swing.DefaultComboBoxModel(new String[]
应该替换为
new javax.swing.DefaultComboBoxModel<String>(new String[]
该警告也可以忽略。