Collections.sort(employees, (employee1, employee2) -> {
return (employee1.getAge() >= employee2.getAge()) ? -1 : 1;
});
The above code sample sorts the 'employees' List according to age just fine. But, the code below gives an error.
Collections.sort(employees, (employee1, employee2) ->
employee1.getAge() >= employee2.getAge() ? -1 : 1;
);
Isn't the ternary operator considered as a single line expression? The error shown is:
java: ')' expected; java: illegal start of expression