Java generics warnings on java.util.Collections

后端 未结 4 1712
生来不讨喜
生来不讨喜 2021-02-19 23:39

I have a method:

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

    return toSort;
}

T

4条回答
  •  执笔经年
    2021-02-20 00:39

    Do tou use this:

    // Bad Code
    public class Stuff implements Comparable{
    
        @Override
        public int compareTo(Object o) {
            // TODO
            return ...
        }
    
    }
    

    or this?

    // GoodCode
    public class Stuff implements Comparable{
    
        @Override
        public int compareTo(Stuff o) {
            // TODO
            return ...
        }
    
    }
    

提交回复
热议问题