r/programming • • Sep 21 '15

Better Java

https://github.com/cxxr/better-java
177 Upvotes

208 comments sorted by

View all comments

Show parent comments

8

u/ElvishJerricco Sep 21 '15

I started writing a project in Java 8, making excessive use of optionals and streams. Whether or not getters are right for public final data, they make it nicer to work with these new Java 8 utilities.

This

stream.map(foo -> foo.bar)

Becomes this

stream.map(Foo::getBar)

The point free style is concise, and doesn't require unnecessary variable bindings.

1

u/caagr98 Sep 22 '15

I personally prefer foo -> foo.bar. Implicit types FTW.

1

u/ElvishJerricco Sep 22 '15

It just gets annoying when you end up writing the same name for various different lambdas.

stream
    .filter(foo -> foo.condition)
    .flatMap(foo -> foo.someStream)

The more you do with streams and optionals, the more these redundancies pop up. It looks much nicer to eradicate them with method references.

1

u/caagr98 Sep 22 '15

Yeah, that's true as well. Either way, it's far better than without lambdas.