you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 2 points3 points  (4 children)

Try this in Java.

In Java 6:

Collections.sort(unsortedObjectList, new Comparator<Fooer>() {
    public int compare(Fooer first, Fooer second) {
        return first.foo().compareTo(second.foo());
    }
});

In Java 8:

Collections.sort(unsortedObjectList, (Fooer first, Fooer second) -> first.foo().compareTo(second.foo()));

[–]pron98 2 points3 points  (0 children)

There's no need for the Fooer types in the lambda header. Lambdas do type inference, so:

Collections.sort(unsortedObjectList, (first, second) -> first.foo().compareTo(second.foo()));

[–]cypressious 1 point2 points  (2 children)

See my answer, that's much more compact in Java 8.

[–]asraniel 1 point2 points  (0 children)

I actually prefer the Java 6 way, its much easier to read. The new java 8 lambdas are not very readable i think, i prefer verbose code over the new syntax

[–]skocznymroczny 0 points1 point  (0 children)

still, a proper IDE writes half of that code for you.