class pair{
int start;
int end;
pair(int start, int end)
{
this.start = start;
this.end = end;
}
}
public class Solution {
public void intervals(ArrayList<Integer> arrive, ArrayList<Integer> depart) {
ArrayList<pair> list = new ArrayList<>();
for(int i=0;i<arrive.size();i++)
{
pair p = new pair(arrive.get(i),depart.get(i));
list.add(p);
}
Collections.sort(list, new Comparator()
{
@Override
public int compare(pair a, pair b)
{
return a.start.compareTo(b.start);
}
});
The error says that a.start is not allowed here. but compareTo should work fine for interger values.
./Solution.java:19: error: <anonymous Solution$1> is not abstract and does not override abstract method compare(Object,Object) in Comparator
{
^
./Solution.java:20: error: method does not override or implement a method from a supertype
@Override
^
./Solution.java:23: error: int cannot be dereferenced
return (a.start).compareTo(b.start);
^
Note: ./Solution.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
3 errors
the Override looks correct to me. I dont know why it's giving error.