Collections.sort(stuGrade_List, new Comparator() { public int compare(Object o1, Object o2) {
stuGrade stu1 = (stuGrade) o1;
stuGrade stu2 = (stuGrade) o2;
                                        //获得语文的成绩,是doubel型
return stu2.getChinese() - stu1.getChinese();
}
});这代码报错 cannot convert from double to int。为什么int可以,double 不可以?怎么解决啊?(我用float型也是同样的问题)

解决方案 »

  1.   

    return (int)stu2.getChinese() - stu1.getChinese(); 
      

  2.   

    return (int)(stu2.getChinese() - stu1.getChinese()); 
      

  3.   

    public int compare(Object o1, Object o2) { 把返回值也改成double
      

  4.   

    这个地方的确应该改,不过改了还是有错- The return type is incompatible with Comparator.compare(Object, Object)
      

  5.   

    就是返回值的问题
    int ->>> double 可以
    double-->>> int 不可隐式转换