Search code examples
javacompiler-warningsunchecked

Unckecked method invocation warning on Collections.sort()


I want to sort a List<MyType> received as a an argument :

static void doSomething(List<MyType> arg) {
    Collections.sort(arg);
}

...but I get this warning :

Unchecked method 'sort(List<T>)' invocation

Here's MyType :

class MyType implements Comparable {
    private int number;

    public MyType(int n) {
        number = n;
    }

    public int compareTo(MyType b) {
        return Integer.compare(number, b.number);
    }
}

I can suppress this warning, but I would like to know what I'm doing wrong.


Solution

  • @Aominè had it right : MyType implemented Comparable instead of Comparable<MyType>. The warning is gone now that I've changed this.