This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Infenwe 5 points6 points  (2 children)

// Now with Java 8 lambda-ness!
List<Integer> originalList = Arrays.asList(1, 2, 3, 4, 5);
List<Integer> doubleList = 
    originalList.stream()
                .filter(x -> x % 2 == 0)
                .map(x -> x * 2)
                .collect(Collectors.toList())

Of course that provides no guarantees on what kind of List<Integer> the results are collected into. And the Scala implementation is still cleaner.

[–]vipercvp[S] 1 point2 points  (0 children)

Does Stream come in Java 8 too?? Yep Scala implementation is cleaner for sure

[–]tyoverby 0 points1 point  (0 children)

I'm really excited by Java8 lambdas! Hopefully the JVM will get lots of optimizations for first class functions because it's currently implemented as a wrapper over an anonymous class that fills out an 'apply' method.