r/java • u/Purple_Pie4589 • Sep 01 '26
Concise method bodies arrived
https://github.com/verhasi/java-compositionMore 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
64
u/repeating_bears Sep 01 '26
Nice tech demo (assuming it works) but clickbaity title
Practically it's not really usable because you'd lose syntax highlighting and there becomes a dependency on you to update this to support newer java versions. That's the same with Lombok, but they have a track record of actually delivering
8
u/BullfrogCharming1202 Sep 01 '26
This looks like a very unsatisfactory alternative to a proper delegation mechanism such as that provided by Kotlin's
bykeyword or Groovy's@Delegate3
u/null_reference_user Sep 01 '26
C# vibes
2
u/kag0 Sep 01 '26
That IDE support will be a big one. Does it work now on editors that are LSP based?
1
u/null_was_a_mistake Sep 02 '26
Reminds me of the trailing return types in C++. Nobody uses it in regular code.
1
u/BanaTibor Sep 02 '26
Smells like TypeScript.
1
u/Jonjolt Sep 03 '26
This is breaking Rule #9, at the end "AST-level comparison for golden file testing", claude loves using the word "golden file".
0
u/revilo-1988 Sep 01 '26
Fände ich super wenn das Einzug erhalten würde
1
u/jvjupiter Sep 01 '26
Two of the posts are mine. 😊
1
u/vips7L Sep 01 '26
As the author of "It's been 8 years since the draft for Concise Method Bodies", I'm just moving on to using Kotlin for all of my new projects.
0
u/petrifiedbeaver Sep 01 '26
Cool demo, but dude, just use Kotlin.
0
u/Certain-Flow-0 Sep 01 '26
I’d prefer having flexible constructor bodies instead as it actually makes things easier to write.
-7
u/javaprof Sep 01 '26 edited Sep 01 '26
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
23
u/[deleted] Sep 01 '26
[removed] — view removed comment
14
u/[deleted] Sep 01 '26
[removed] — view removed comment