我知道这已被问过1000次,我已经看到1000个答案,但我没有看到任何实际为我工作的。 我必须对实现我自己的接口的对象列表进行排序。我决定为这些对象扩展Comparable接口并实现compareTo方法。 我的界面: public interface Field extends Comparable<Field> {
}
我的对象类 public class ConcreteField
我想这些时间,以便进行排序: 4:05 AM
5:04 PM
6:04 AM
4:05 PM
5:04 AM
12:01 AM
12:01 PM
使用Time类 public int compareTo(Time t)
方法。 if(this.getMeridians() != t.getMeridians())
return this.getMeridians().
public class Book implements Comparable<Book>, Serializable{
int numberOfPages;
boolean hardback;
String title;
double price;
public Book (int numberOfPages,boolean hardback, String title,double
我需要建立一个类Course它有一个通用字段(我不能添加另一个字段包含Comparator)。 我需要一个Comparator到类Course使用它自己的CompareTo方法,使其能够比较通用的领域(如String-compareTo的字符串,如果整型等): 的评判getGeneric()回报通用领域。 new Comparator<Course<?>>({
public int co
EventObject target = new EventObject("e2");
Set<EventObject> Following = o.getFollowingEvents(e1);
System.out.println("Elements : "+Following.toString());
System.out.println(e2.toString());
System