I'm trying to wrap my brain around how to use effectively use MethodHandles, one thing that's throwing me off is trying to execute MethodHandles during debugging. Here's some example code which illustrates my issue.
public class MetricianTest {
public static void main(String[] args) throws Throwable {
final MethodHandles.Lookup lookup = MethodHandles.lookup();
final MethodType mt = MethodType.methodType(String.class);
final MethodHandle mh = lookup.findVirtual(MHTestClass.class, "testMethod", mt);
System.out.println(mh.invoke(new MHTestClass()));
}
public static class MHTestClass {
public int testField = 1;
public MHTestClass() {
}
public String testMethod() {
return "method-value";
}
}
}
The code works when running normally, but stopping the IntelliJ debugger and attempting to invoke the MethodHandle throws an UnsupportedOperationException. Looking at the Javadocs, I can see that MethodHandles cannot be invoked reflectively, but I'm not sure I understand why, or how to go about debugging MethodHandle invocations in my program. Any insight would be greatly appreciated!