相关疑难解决方法(0)

java.util.Collections上的Java泛型警告

我有一个方法:

public List<Stuff> sortStuff(List<Stuff> toSort) {
    java.util.Collections.sort(toSort);

    return toSort;
}
Run Code Online (Sandbox Code Playgroud)

这会产生一个警告:

Type safety: Unchecked invocation sort(List<Stuff>) of the generic method sort(List<T>) of type Collections.
Run Code Online (Sandbox Code Playgroud)

Eclipse说修复警告的唯一方法是添加@SuppressWarnings("unchecked")到我的sortStuff方法中.对于Java本身内置的东西来说,这似乎是一种糟糕的方式.

这真的是我唯一的选择吗?为什么或者为什么不?提前致谢!

java generics collections

11
推荐指数
2
解决办法
7611
查看次数

标签 统计

collections ×1

generics ×1

java ×1