-4

.\StartComparator.java:3: error: StartComparator is not abstract and does not override abstract method compare(Object,Object) in Comparator

.\StartComparator.java:5: error: method does not override or implement a method from a supertype @Override

import java.util.Comparator;

public class StartComparator<T> implements Comparator
{
    @Override
    public int compare(TimeLineChunk<T> o1, TimeLineChunk<T> o2) {
        return o1.Start.compareTo(o2.Start);
    }
}

I am not exactly sure why it is throwing these errors, they seem to contradict each other.

Alexander
  • 19,906
  • 19
  • 75
  • 162
  • 1
    `TimeLineChunk` is not a supertype of object. It wants an `Object`. So you're not actually implementing `Comparator` (1). Instead you're overriding something non-existent, either by implementing or extending. (2). Are you looking for `Comparator>` by any chance? – Caramiriel Jun 19 '16 at 21:29
  • 1
    [What is a raw type and why shouldn't we use it?](http://stackoverflow.com/q/2770321) – Tom Jun 19 '16 at 21:40
  • Thank you for all the answers, they fixed my problem. I am not quite sure why the question is at -4. I had a problem which is clearly stated, I included the error message, I provided the relevant code... what else could I have done? I am a Java generics beginner and, by myself, wouldn't have found the issue. – Alexander Jun 20 '16 at 06:43

2 Answers2

3

The complaints are related. The second is telling you that your method doesn't override any method. Hence it is not (correctly) overriding compare, which is the first complaint.

Most likely you need to declare the implements method with the correct type parameter: implements Comparable<TimeLineChunk<T>>. Your compiler should have warned you about the raw type use of Comparable.

BeeOnRope
  • 60,350
  • 16
  • 207
  • 386
1

You are not overriding compare method, it's just an overloaded version. Your arguments type should be "Object", not TimeLineChunk.

TomekK
  • 403
  • 1
  • 4
  • 11
  • Well it would be better not to use raw `Comparable` type in the first place, by properly parametrizing it. – BeeOnRope Jun 19 '16 at 21:37