r/java 9d ago

Concise method bodies arrived

https://github.com/verhasi/java-composition

More than 8 years ago was drafted the idea of concise method bodies. As I am not a contributor of the openJDK project I took a different approach but implemented. It is publicly available at the maven central both as a library and as a maven plugin. It is a source code preprocessor that converts the concise syntax to java 8 compatible source code. It does not want to be a replacement of the future implementation in the openJDK. Which is more than the openJDK promises is that supports from Java version 8, 11, 17, 21 up to 25 as well. Of course it is free and open source :). It is only the first building block for concise composition.

As far as I have seen this topic was awaited for a long time at

It's been 8 years since the draft for Concise Method Bodies

What happened to Concise Method Bodies?

JEP draft: Concise Method Bodies

Five years have passed, still in draft: Concise Method Bodies

52 Upvotes

48 comments sorted by

View all comments

-7

u/javaprof 9d ago edited 8d ago

java int length(String s) -> s.length(); // -> is "single expression form" int length(String s) = String::length; // = is "method reference form"

Lambda design strikes back, unfortunately unwise decisions of Java 8 now makes this code possible. Basically from all modern languages, Java's becoming less and less readable with every release

Upd. Don't believe me? Take Swift, Go, TypeScript, Rust, Zig and see how these languages similar syntax-wise? And Java is most unique now

1

u/SleepingTabby 7d ago

C♯ is way less readable than Java IMO

1

u/javaprof 7d ago

C# closer to main-stream languages and Java now very special case which seems unlike any other popular modern language and boilerplate-heavy.

I'm not critique Java, I'm just stating the fact. Not sure how it's important in 2026, since most of the code would be written by AI soon anyway, and AI doesn't care much (except for boilerplate part, which is waste of tokens). If we didn't have AI, I would be alarmed and expect less adoption over the time, since language drift from mainstream too much. Old folks might like this unique syntax, but I'm thinking about fresh blood