No need to have a class (or 2) ‘including’ the
java.util.concurrent.Callable for the submit method, since JRuby passes
the block as an implementation of the (last) interface argument.
Great way to ease scripting over Java APIs that has been available since ancient
However, there’s been some collisions notably around on Java 8’s novel stream
support where Ruby block semantics otherwise match up very well with functional interfaces.
The problem is that proc-to-interface dispatch logic is using method_missing,
thus a potential naming conflict (either from a core extending gem or built-in method)
fails to execute the intended logic e.g. a block-based implementation for Predicate#test
ends up calling Ruby’s Kernel#test instead of the actual body (the bellow
example would fail).
This has been improved in JRuby 9.1 to always bind concrete (implemented) interface
methods, besides method_missing, to make sure the intended block body is executed
regardless of the inherited runtime state. Looks and feels just like Java these days.
Make sure you have JRuby >= 9.1 when scripting functional Java, like above.
If you'd like to dive deep once again or need JRuby help, you're at the right place.