【问题标题】:Unchecked warnings are not removed with Javac @SuppressWarnings annotationJavac @SuppressWarnings 注释不会删除未经检查的警告
【发布时间】:2015-06-08 19:27:48
【问题描述】:

我无法通过未经检查的演员来删除我的警告。我相信这很奇怪,因为我在方法上添加了@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";
}

谢谢。

【问题讨论】:

  • 你能让你的标题更具描述性吗?
  • @kolossus,它在问题中说来自 Oracle 的 1.7u79。
  • 我正在使用 Oracle JDK 1.7 更新 79
  • @rvillablanca,1.8.0_45 似乎无法重现。
  • 你是对的,可能是 JDK 7 的错误??

标签: java compilation warnings javac compiler-warnings


【解决方案1】:

这看起来像一个javac 错误。但它不会在 1.8.0u45 中重现。

进行了快速搜索,它可能与 JDK-8016099JDK-8022144 相关。可以做一个 hg bisect 来找到解决问题的确切变更集。

可能相关:

【讨论】:

    猜你喜欢
    • 2015-02-25
    • 1970-01-01
    • 2013-06-05
    • 2012-03-25
    • 2015-09-20
    • 1970-01-01
    • 2015-05-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多