我有以下代码:
private static final Set<String> allowedParameters;
static {
Set<String> tmpSet = new HashSet();
tmpSet.add("aaa");
allowedParameters = Collections.unmodifiableSet(tmpSet);
}
它导致:
Note: mygame/Game.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
当我使用建议的选项重新编译时,我看到一个指针 (^) 指向 HashSet();
前面的“new”。
有人知道这是怎么回事吗?
最佳答案
是的,您正在创建一个新的 HashSet,但没有说明它应该包含什么类,然后断言它包含字符串。改成
Set<String> tmpSet = new HashSet<String>();
关于java - 什么是乱操作、不安全操作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2419216/