什么是未经检查和不安全的操作? [英] What is unchecked and unsafe operation here?

查看:161
本文介绍了什么是未经检查和不安全的操作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码:

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

And when I recompile with the suggested option I see a pointer (^) pointing at "new" in front of HashSet();.

有人知道这是怎么回事吗?

Does anybody know what is going on here?

推荐答案

是的,你正在创建一个新的HashSet,而不说明它应该包含什么类,然后断言它包含字符串。将其更改为

Yes, you're creating a new HashSet without stating what class it should contain, and then asserting that it contains strings. Change it to

 Set<String> tmpSet = new HashSet<String>();

这篇关于什么是未经检查和不安全的操作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆