未使用 Javac @SuppressWarnings 注释删除未经检查的警告
Unchecked warnings are not removed with Javac @SuppressWarnings annotation
我无法删除未经检查的转换警告。我认为这很奇怪,因为我在方法上添加了 @SuppressWarnings("unchecked")
注释,但 Javac 仍然显示警告。
[unchecked] unchecked cast (List<Integer>) getObject(LIST);
return (List<Integer>) getObject(LIST);
required: List<Integer>
found: Object
我创建了一个示例,它抛出 2 个警告。我正在使用 Oracle JDK 1.7 更新 79.
package strange;
import java.util.List;
public class Strange implements Constants {
//Throw Warning
@SuppressWarnings("unchecked")
protected List<Integer> getList() {
return (List<Integer>) getObject(LIST);
}
@SuppressWarnings("unchecked")
protected List<Integer> getList2() {
return (List<Integer>) getObject(LIST);
}
//Throw Warning
@SuppressWarnings("unchecked")
protected List<Integer> getOtherList() {
return (List<Integer>) getObject(OTHER);
}
protected Object getObject(String key) {
return new Object();
}
}
interface Constants {
public static final String LIST = "list";
public static final String OTHER = "other";
}
谢谢。
这看起来像一个 javac
错误。不过它不会在 1.8.0u45 中重现。
进行了快速搜索,它可能与 JDK-8016099 or JDK-8022144 等相关。可以执行 hg bisect 以找到解决问题的确切变更集。
可能相关:
- Java generics SuppressWarnings("unchecked") mystery
我无法删除未经检查的转换警告。我认为这很奇怪,因为我在方法上添加了 @SuppressWarnings("unchecked")
注释,但 Javac 仍然显示警告。
[unchecked] unchecked cast (List<Integer>) getObject(LIST);
return (List<Integer>) getObject(LIST);
required: List<Integer>
found: Object
我创建了一个示例,它抛出 2 个警告。我正在使用 Oracle JDK 1.7 更新 79.
package strange;
import java.util.List;
public class Strange implements Constants {
//Throw Warning
@SuppressWarnings("unchecked")
protected List<Integer> getList() {
return (List<Integer>) getObject(LIST);
}
@SuppressWarnings("unchecked")
protected List<Integer> getList2() {
return (List<Integer>) getObject(LIST);
}
//Throw Warning
@SuppressWarnings("unchecked")
protected List<Integer> getOtherList() {
return (List<Integer>) getObject(OTHER);
}
protected Object getObject(String key) {
return new Object();
}
}
interface Constants {
public static final String LIST = "list";
public static final String OTHER = "other";
}
谢谢。
这看起来像一个 javac
错误。不过它不会在 1.8.0u45 中重现。
进行了快速搜索,它可能与 JDK-8016099 or JDK-8022144 等相关。可以执行 hg bisect 以找到解决问题的确切变更集。
可能相关:
- Java generics SuppressWarnings("unchecked") mystery