-
Bug
-
Resolution: Fixed
-
P4
-
19
-
None
-
b26
| Welcome to JShell -- Version 19
| For an introduction type: /help intro
jshell> import java.lang.invoke.*;
jshell> class C { static void test() throws Throwable {
...> MethodHandles.Lookup lookup = MethodHandles.lookup();
...> MethodHandle mh = lookup.findSpecial(Object.class, "toString", MethodType.methodType(String.class), C.class);
...> System.out.println(mh.invoke(new C()));
...> }}
| created class C
jshell> C.test()
REPL.$JShell$17$C@b1bc7ed
jshell> interface I { static void test() throws Throwable {
...> MethodHandles.Lookup lookup = MethodHandles.lookup();
...> MethodHandle mh = lookup.findSpecial(Object.class, "toString", MethodType.methodType(String.class), I.class);
...> System.out.println(mh.invoke(new I(){}));
...> }}
| created interface I
jshell> I.test()
| Exception java.lang.IllegalArgumentException: nothing to resolve
| at MethodHandleNatives.resolve (Native Method)
| at MemberName$Factory.resolve (MemberName.java:1085)
| at MemberName$Factory.resolveOrNull (MemberName.java:1129)
| at MethodHandles$Lookup.getDirectMethodCommon (MethodHandles.java:4010)
| at MethodHandles$Lookup.getDirectMethod (MethodHandles.java:3963)
| at MethodHandles$Lookup.findSpecial (MethodHandles.java:3012)
| at I.test (#4:3)
| at (#5:1)
There's no particular reason that an interface shouldn't be able to make the same 'findSpecial' request as a class. I believe this 'findSpecial' call should succeed.
| For an introduction type: /help intro
jshell> import java.lang.invoke.*;
jshell> class C { static void test() throws Throwable {
...> MethodHandles.Lookup lookup = MethodHandles.lookup();
...> MethodHandle mh = lookup.findSpecial(Object.class, "toString", MethodType.methodType(String.class), C.class);
...> System.out.println(mh.invoke(new C()));
...> }}
| created class C
jshell> C.test()
REPL.$JShell$17$C@b1bc7ed
jshell> interface I { static void test() throws Throwable {
...> MethodHandles.Lookup lookup = MethodHandles.lookup();
...> MethodHandle mh = lookup.findSpecial(Object.class, "toString", MethodType.methodType(String.class), I.class);
...> System.out.println(mh.invoke(new I(){}));
...> }}
| created interface I
jshell> I.test()
| Exception java.lang.IllegalArgumentException: nothing to resolve
| at MethodHandleNatives.resolve (Native Method)
| at MemberName$Factory.resolve (MemberName.java:1085)
| at MemberName$Factory.resolveOrNull (MemberName.java:1129)
| at MethodHandles$Lookup.getDirectMethodCommon (MethodHandles.java:4010)
| at MethodHandles$Lookup.getDirectMethod (MethodHandles.java:3963)
| at MethodHandles$Lookup.findSpecial (MethodHandles.java:3012)
| at I.test (#4:3)
| at (#5:1)
There's no particular reason that an interface shouldn't be able to make the same 'findSpecial' request as a class. I believe this 'findSpecial' call should succeed.