表达式的非法开头和';'预期误差
Illegal start of expression and ';' expected error
我遇到了非法的表达式开头和 ;
预期的错误。我搜索了类似的问题,但无法解决我的问题。
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
应该类似地修复。
我遇到了非法的表达式开头和 ;
预期的错误。我搜索了类似的问题,但无法解决我的问题。
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
应该类似地修复。