例如:
javac Foo.java
Note: Foo.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
例如:
javac Foo.java
Note: Foo.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
当前回答
对于Android Studio,你需要添加:
allprojects {
gradle.projectsEvaluated {
tasks.withType(JavaCompile) {
options.compilerArgs << "-Xlint:unchecked"
}
}
// ...
}
在项目的构建中。Gradle文件来了解这个错误是在哪里产生的。
其他回答
我有ArrayList<Map<String,对象>> items = (ArrayList<Map<String,对象>>)值;因为value是一个复杂的结构(我想要清除JSON),可以在数字、布尔值、字符串、数组上发生任何组合。所以,我使用了@Dan Dyer的解决方案:
@SuppressWarnings("unchecked")
ArrayList<Map<String, Object>> items = (ArrayList<Map<String, Object>>) value;
“未检查或不安全操作”警告是在java添加泛型时添加的,如果我没记错的话。它通常要求你以这样或那样的方式更明确地说明类型。
为例。foo = new ArrayList();触发该警告,因为javac正在寻找ArrayList<String> foo = new ArrayList<String>();
对于Android Studio,你需要添加:
allprojects {
gradle.projectsEvaluated {
tasks.withType(JavaCompile) {
options.compilerArgs << "-Xlint:unchecked"
}
}
// ...
}
在项目的构建中。Gradle文件来了解这个错误是在哪里产生的。
你可以保持它的一般形式,并将其写成:
// list 2 is made generic and can store any type of Object
ArrayList<Object> list2 = new ArrayList<Object>();
将数组列表的类型设置为对象使我们能够存储任何类型的数据。你不需要使用-Xlint或其他任何东西。
我上了两年前的课,也上了一些新课。我在Android Studio中解决了这个问题:
allprojects {
gradle.projectsEvaluated {
tasks.withType(JavaCompile) {
options.compilerArgs << "-Xlint:unchecked"
}
}
}
在我的项目构建中。gradle文件(Borzh解决方案)
如果还剩下一些methods:
@SuppressWarnings("unchecked")
public void myMethod()
{
//...
}