黑马程序员技术交流社区

标题: 哈尔滨校区 eclipseF3不显示源代码怎么回事啊? [打印本页]

作者: 陈胜    时间: 2016-1-26 23:47
标题: 哈尔滨校区 eclipseF3不显示源代码怎么回事啊?
本帖最后由 陈胜 于 2016-2-29 23:26 编辑

eclipseF3不显示源代码怎么回事啊?

作者: Mayer    时间: 2016-1-27 09:55
instanceof 运算符是用来在运行时指出对象是否是特定类的一个实例。

  1. class Student implements Comparable//该接口强制让学生具备比较性。
  2. {
  3.         private String name;
  4.         private int age;

  5.         Student(String name,int age)
  6.         {
  7.                 this.name = name;
  8.                 this.age = age;
  9.         }

  10.         public int compareTo(Object obj)
  11.         {

  12.                 //return 0;
  13.                
  14.                 if(!(obj instanceof Student))
  15.                         throw new RuntimeException("不是学生对象");
  16.                 Student s = (Student)obj;

  17.                 System.out.println(this.name+"....compareto....."+s.name);
  18.                 if(this.age>s.age)
  19.                         return 1;
  20.                 if(this.age==s.age)
  21.                 {
  22.                         return this.name.compareTo(s.name);
  23.                 }
  24.                 return -1;
  25.                 /**/
  26.         }

  27.         public String getName()
  28.         {
  29.                 return name;

  30.         }
  31.         public int getAge()
  32.         {
  33.                 return age;
  34.         }
  35. }
复制代码

作者: 陈胜    时间: 2016-1-28 00:18
   。。。?




欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2