Java Magazine, Nov/Dec 2017
ORACLE COM JAVAMAGAZINE NOVEMBER DECEMBER 2017 73 inside the jvm catch NoSuchMethodException IllegalAccessException mhx throw new AssertionError initCause mhx return mh The handle can then be invoked in a similar way to a reflective call A receiver object must be supplied for instance methods and the invocation code must deal with the possibility of a coarse grained exception MethodHandle mh getToStringMH try mh invoke this null catch Throwable e e printStackTrace The concept of a BSM should now be clear when program control reaches an invokedynamic call site for the first time the associated BSM is called The BSM returns a call site object containing a method handle to the method that will actually be bound into the call site For this mechanism to function correctly with static typing the BSM must return a handle to a method of the correct method signature To get back to the lambda expression example I gave earlier you can think of the invokedynamic opcode as representing a call to some sort of platform factory method for a lambda expression The actual body of the lambda has been transformed into a private static method on the class where the lambda is defined private static void lambda main 0 Code
You must have JavaScript enabled to view digital editions.