I'm trying to sort an array of objects according to the DateTime of the objects. I've used the following example to create my solution:
Sort objects in ArrayList by date?
The method I use looks like this:
List<SomeEvent> myEvents = new ArrayList<>();
//...
//left out the part where the List is filled with Objects
//...
Collections.sort(myEvents, new Comparator<SomeEvent>() {
public int compare(SomeEvent se1, SomeEvent se2) {
return se1.getStartTime().compareTo(se2.getStartTime());
}
});
I get the error message "Cannot resolve method 'compareTo(com.google.api.client.util.DateTime)'
Any pointers as to what I'm missing?
Edit: My class SomeEvent now implements Comparable as suggested:
public class SomeEvent extends SomeTask implements Comparable<SomeEvent>
{
private DateTime startTime;
private DateTime endTime;
public DateTime getStartTime() {
return startTime;
}
public DateTime getEndTime() {
return endTime;
}
}
Now, however, I get the hint that I need to either declare my class as abstract (which is not possible in the context it is used) or implement the abstract method 'compareTo(T)' in 'Comparable'.
How can I implement the abstract method?