当前位置: 代码迷 >> J2SE >> 请教为什么这个程序没有报错并且也没有运行结果呢?多谢
  详细解决方案

请教为什么这个程序没有报错并且也没有运行结果呢?多谢

热度:153   发布时间:2016-04-24 02:28:31.0
请问为什么这个程序没有报错并且也没有运行结果呢?谢谢!
public class C{
  public static void main(String args[]){
  Integer i=new Integer(1);
  Integer j=new Integer(2);
  j.compareTo(new Integer(3));
  j.compareTo(i);
  }
}

------解决方案--------------------
public class C {
public static void main(String args[]) {
Integer i = new Integer(1);
Integer j = new Integer(2);
System.out.println(j.compareTo(new Integer(3)));
System.out.println(j.compareTo(i));
}
}
打印出来是有比较的,为什么会报错。。你也可以自己实现comparable接口
  相关解决方案