r/java 20h 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

41 Upvotes

29 comments sorted by

View all comments

6

u/BullfrogCharming1202 17h ago

This looks like a very unsatisfactory alternative to a proper delegation mechanism such as that provided by Kotlin's by keyword or Groovy's @Delegate

2

u/jvandort 16h ago

Yeah to me concise method bodies would be most useful in the delegation pattern, removing a lot of boilerplate. With composition > inheritance the delegation pattern becomes much more common and if I could pick a first-class delegation syntax or a concise method bodies syntax I'd prefer delegation

1

u/null_was_a_mistake 2h ago

Scala 3 now has an export keyword. Anything that you can import can be exported as class members and also implement interfaces. You can easily pick what to export and what not to. I quite like it for making delegates.