Java “unchecked call to compareTo(T) as a member of the raw type java.lang.Comparable”

后端 未结 3 1765
無奈伤痛
無奈伤痛 2021-02-05 04:54

I\'m trying to implement a sorted list as a simple exercise in Java. To make it generic I have an add(Comparable obj) so I can use it with any class that implements

3条回答
  •  渐次进展
    2021-02-05 05:18

    You need to "check" or define the Comparable object like so:

    add(Comparable obj)
    
        

    提交回复
    热议问题