【发布时间】:2013-03-08 06:26:56
【问题描述】:
我有一个方法:
public List<Stuff> sortStuff(List<Stuff> toSort) {
java.util.Collections.sort(toSort);
return toSort;
}
这会产生一个警告:
Type safety: Unchecked invocation sort(List<Stuff>) of the generic method sort(List<T>) of type Collections.
Eclipse 说修复警告的唯一方法是将@SuppressWarnings("unchecked") 添加到我的sortStuff 方法中。对于 Java 本身内置的东西,这似乎是一种糟糕的方式。
这真的是我唯一的选择吗?为什么或者为什么不?提前致谢!
【问题讨论】:
-
这是产生错误的实际代码吗?查看“Stuff”的代码可能会有所帮助。
标签: java generics collections