I am getting the illegal start of expression and ;
expected errors. I searched for similar problems but I couldn't solve my problem.
public int compare(Point point1, Point point2)
Here is the full method.
public static void sortByX(List<? extends Point> points)
{
Collections.sort(points, new Comparator<Point>() );
{
public int compare(Point point1, Point point2)
{
if (point1.x < point2.x)
return -1;
if (point1.x > point2.x)
return 1;
return 0;
}
}
}
public static void sortByY(List<? extends Point> points)
{
Collections.sort(points, new Comparator<Point>() );
{
public int compare(Point point1, Point point2)
{
if (point1.y < point2.y)
return -1;
if (point1.y > point2.y)
return 1;
return 0;
}
}
}
You have );
in the wrong place. They should appear following the anonymous implementation of Comparator<Point>()
:
public static void sortByX(List<? extends Point> points)
{
Collections.sort(points,
new Comparator<Point>() //); - remove these
{
public int compare(Point point1, Point point2)
{
if (point1.x < point2.x)
return -1;
if (point1.x > point2.x)
return 1;
return 0;
}
}); // add ); here
}
sortByY
should be fixed similarly.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments