我遇到了表达式的非法开始和 ;
预期的错误。我搜索了类似的问题,但无法解决我的问题。
public int compare(Point point1, Point point2)
这是完整的方法。
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;
}
}
}
最佳答案
你有 );
在错误的地方。它们应该在 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
应该类似地修复。
关于java - 表达式的非法开始和 ';' 预期错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30433015/