Can I use compareTo to sort integer and double values?

后端 未结 4 2039
天命终不由人
天命终不由人 2020-12-10 03:52

Can I use compareTo to sort integer and double values? My system gives me an error that I Cannot invoke compareTo(int) on the primitive type int. any ideas?

Code:

4条回答
  •  旧巷少年郎
    2020-12-10 04:38

    In your current code; easier solution would be to just change this line and all will be good:

    return o1C.getPrice() - o2C.getPrice() ;
    

    This would work fine and good performance too because method compare() has only following requirement viz. return zero if both values are equal; else a positive/negative number.

提交回复
热议问题