Java generics warnings on java.util.Collections
collections, generics, java
Solution
`Collections.sort(List<T>)` expects that `T` must implement `Comparable<? super T>`. It seems like `Stuff` does implement `Comparable` but doesn't provide the generic type argument.
Make sure to declare this:
public class Stuff implements Comparable<Stuff>
Instead of this:
public class Stuff implements Comparable
Problem
I have a method: ``` public List<Stuff> sortStuff(List<Stuff> toSort) { java.util.Collections.sort(toSort); return toSort; } ``` This produces a warning: ``` Type safety: Unchecked invocation sort(List<Stuff>) of the generic method sort(List<T>) of type Collections. ``` Eclipse says the only way to fix the warning is to add `@SuppressWarnings("unchecked")` to my `sortStuff` method. That seems like a crummy way to do with something that is built into Java itself. Is this really my only option here? Why or why not? Thanks in advance!