General issues:
- Using the syntax
object::aMethod can it be converted to a type, such as MethodHandle , as a functional interface? - If not, how can you indirectly call a method reference in Java 8?
As an example, suppose we would like to have a MethodRefRunner like:
class MethodRefRunner { static void execute(Object target, WHATTYPE mref, Object... args) { mref.apply(args); } }
And it can be used like: MethodRefRunner.execute(o, o::someMethod, someParam)
In the above snippet, one parameter for WHATTYPE is java.util.function.Function , but very restrictive. As stated in this answer , prior to version b75, java.util.function.Block existed, and this can be convenient.
On the other hand, is there any chance that WHATTYPE could be somehow converted to java.lang.invoke.MethodHandle ?
Note to Java experts: Refine the title of the questions as needed.
java lambda java-8
nobeh Jun 17 '13 at 8:16 2013-06-17 08:16
source share