I am a very heavy user of Java reflection. I think we all agree the syntax is a tad less than user friendly but worst of all, you need to use strings all the time. Clearly this is error prone.
Since Java 8 we've got lambdas! They have a nice syntax to reference methods:
interface A { String foo(); }
We can then refer to the foo
method with A::foo
.
void inspect( Function<A,String> f) { }
void test() {
inspect(A::foo);
}
Unfortunately, the compiler and the runtime seem to go out of their way to hide any reference to the underlying method A::foo
. I'd first naively hoped that the MethodHandlesProxies
class would be used to create the lambda but the isWrapperInstance
method returns false
so they use an internal mechanism.
Now although I realize that it would mean create functional interfaces for each invocation order, I still really like this syntax so much that I really want to use it.
I tried:
- `MethodHandlesProxies.isWrapperInstance
- `Lookup.revealDirect(..).reflectAs
Anybody any ideas how to find the underlying method that backs the lambda?