MethodHandles を効果的に使用する方法について頭を悩ませようとしています。私の問題を説明するコード例を次に示します。
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がスローされます。Javadoc を見ると、MethodHandles をリフレクティブに呼び出すことができないことがわかりますが、その理由や、プログラムで MethodHandle 呼び出しをデバッグする方法を理解しているかどうかはわかりません。どんな洞察も大歓迎です!