标签:oid stat class ble java todo str 方便 override
package test0; import java.util.Comparator; //限定修饰符为friend不能为public,一个java文件中只能有一个public类 /*** * java程序是从一个public类的main函数开始执行的, *(其实是main线程),就像c程序是从main()函数开始执行一样。 * 只能有一个public类是为了给类装载器提供方便。 */ interface MyComparable<T>{ //接口类--抽象类 public int compare(T agr0); //抽象方法--在子类中实现 } class student implements Comparable<student> { private String name="zhang"; private int num=12; @Override public String toString() { return "名字为:" + name +","+ "学号为:" + num; } @Override public int compareTo(student arg0) { return this.num-arg0.num; } } class teacher implements Comparator<student> { private String name="zhang"; private int num=12; @Override public String toString() { return "名字为:" + name +","+ "学号为:" + num; } @Override public int compare(student arg0, student arg1) { // TODO Auto-generated method stub return 0; } } public class Test { public static void main(String[] args) { teacher space=new teacher(); } }
Java的比较接口comparable与comparator
标签:oid stat class ble java todo str 方便 override
原文地址:https://www.cnblogs.com/z2529827226/p/11638527.html