简体   繁体   English

表达式的开头和';'不合法 预期误差

[英]Illegal start of expression and ';' expected error

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>() : 它们应出现在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. sortByY应该类似地固定。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM