0
我正試圖圍繞如何有效地使用MethodHandles來解決我的大腦問題,有一件事讓我想起了在調試過程中試圖執行MethodHandles。 下面是一些說明我的問題的示例代碼。在調試過程中調用MethodHandle
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";
}
}
}
代碼正常運行時,但停止的IntelliJ調試器,並試圖調用MethodHandle拋出UnsupportedOperationException異常工作。看着Javadocs,我可以看到MethodHandles不能被反射調用,但我不確定我是否理解爲什麼,或者如何去調試我的程序中的MethodHandle調用。任何有識之士將不勝感激!
太棒了!感謝您的快速回復! – nickrobison