Can I use compareTo to sort integer and double values?

后端 未结 4 2043
天命终不由人
天命终不由人 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:34

    Change the code

    int price;  
    

    to

    Integer price;
    

    because primitive types such as int will not support any methods, like compareTo().

提交回复
热议问题