How do you use generic interfaces in Java 1.5?
December 13, 2005 11:34 AM
Subscribe
How do you use generic interfaces in Java 1.5?
I'm trying to write a class that implements the Comparable interface in Java 1.5, and the compile errors are bewildering. In 1.4.2, you could write something like
class MyEvent implements Comparable {
double time;
public MyEvent(double t) {
time = t;
}
public int compareTo(Object o) {
double otherTime = ((MyEvent)o).time;
return new Double(time).compareTo(new Double(otherTime));
}
}
But I can't seem to figure out how to do this in Java 1.5. How do you write a class that is Comparable to itself? In case its relevent, I ask because I'd like to store instances of something like the above in a PriorityQueue. Thanks!
posted by gsteff to computers & internet (5 comments total)
posted by andrew cooke at 11:57 AM on December 13, 2005