The general questions are:
- When using the syntax
object::aMethod
, can it be converted to a type such as MethodHandle
as a functional interface?
- If no, how can a method reference be indirectly invoked in Java 8 if at all possible?
As an example, imagine we'd like to have a MethodRefRunner
as:
class MethodRefRunner {
static void execute(Object target, WHATTYPE mref, Object... args) {
mref.apply(args);
}
}
And it can be used as: MethodRefRunner.execute(o, o::someMethod, someParam)
In the above snippet, one option for WHATTYPE
is java.util.function.Function
but very restrictive. As this answer mentions, prior to version b75, there was a java.util.function.Block
was available and might be handy.
On the other side, any chance that WHATTYPE
could be in some way converted to a java.lang.invoke.MethodHandle
?
Note to Java experts: Please refine the title of the questions as needed.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…