Illegal start of expression and ';' expected error

rumay

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;
        }
    }
}
Eran

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.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

'Try without catch error', ')' expected, illegal start of expression..?

From Dev

Java Error: illegal start of expression

From Dev

java illegal start of expression error

From Dev

Receiving Illegal start of expression error

From Dev

Illegal start of expression error in Java

From Dev

java illegal start of expression error

From Dev

"Illegal start of expression" error in Java

From Dev

Why is "error: illegal start of simple expression" for reduceByKey?

From Dev

error: illegal start of expression in Android Studio Code

From Dev

Weird "illegal start of expression" error in Netbeans

From Dev

How to fix illegal start of expression compilation error?

From Dev

Error code compiling: illegal start of expression

From Dev

Error: illegal start of expression followed by PriorityQueue

From Dev

Illegal start of expression string

From Dev

"Illegal start of expression" in "private"

From Dev

Illegal start of expression (method)

From Dev

What's wrong with my java program, "illegal start of expression error"

From Dev

Netbeans is giving me "illegal start of expression" error message on my methods

From Dev

I keep getting an "illegal start of expression" error on my code

From Dev

What's wrong with my java program, "illegal start of expression error"

From Dev

Netbeans is giving me "illegal start of expression" error message on my methods

From Dev

java error in for loop condition evaluation: not a statement, illegal start of expression

From Dev

Jagged Array: Illegal Start of Expression

From Dev

Java Errors Illegal Start of Expression

From Dev

Illegal Start of Expression, trying to print

From Dev

Why is this an illegal start of expression?and not a statement?

From Dev

error: illegal start of type

From Dev

Netbeans "illegal start of type" error

From Dev

JSP Error "Illegal start of type"

Related Related

  1. 1

    'Try without catch error', ')' expected, illegal start of expression..?

  2. 2

    Java Error: illegal start of expression

  3. 3

    java illegal start of expression error

  4. 4

    Receiving Illegal start of expression error

  5. 5

    Illegal start of expression error in Java

  6. 6

    java illegal start of expression error

  7. 7

    "Illegal start of expression" error in Java

  8. 8

    Why is "error: illegal start of simple expression" for reduceByKey?

  9. 9

    error: illegal start of expression in Android Studio Code

  10. 10

    Weird "illegal start of expression" error in Netbeans

  11. 11

    How to fix illegal start of expression compilation error?

  12. 12

    Error code compiling: illegal start of expression

  13. 13

    Error: illegal start of expression followed by PriorityQueue

  14. 14

    Illegal start of expression string

  15. 15

    "Illegal start of expression" in "private"

  16. 16

    Illegal start of expression (method)

  17. 17

    What's wrong with my java program, "illegal start of expression error"

  18. 18

    Netbeans is giving me "illegal start of expression" error message on my methods

  19. 19

    I keep getting an "illegal start of expression" error on my code

  20. 20

    What's wrong with my java program, "illegal start of expression error"

  21. 21

    Netbeans is giving me "illegal start of expression" error message on my methods

  22. 22

    java error in for loop condition evaluation: not a statement, illegal start of expression

  23. 23

    Jagged Array: Illegal Start of Expression

  24. 24

    Java Errors Illegal Start of Expression

  25. 25

    Illegal Start of Expression, trying to print

  26. 26

    Why is this an illegal start of expression?and not a statement?

  27. 27

    error: illegal start of type

  28. 28

    Netbeans "illegal start of type" error

  29. 29

    JSP Error "Illegal start of type"

HotTag

Archive