It isn't pretty, but one can try to achieve a similar approach.
https://godbolt.org/z/TjPha3obs
Failing that, there are always Clojure, Kotlin and Scala on the JVM, which expose language features to achieve the same, which you naturally can mix and match with plain old Java.