Java Magazine, Nov/Dec 2017
ORACLE COM JAVAMAGAZINE NOVEMBER DECEMBER 2017 74 inside the jvm 0 getstatic 7 Field java lang System out Ljava io PrintStream 3 ldc 9 String Hello 5 invokevirtual 10 Method java io PrintStream println Ljava lang String V 8 return The lambda factory will return an instance of some type that implements Runnable and the run method of that type will call back to this private method when the lambda is executed Using javap v to look inside the constant pool shows this entry 2 InvokeDynamic 0 40 0 run Ljava lang Runnable Looking at the BSM section of the class file shows the factory that is being called BootstrapMethods 0 37 REF_ invokeStatic java lang invoke LambdaMetafactory metafactory Ljava lang invoke MethodH andles Lookup Ljava lang String Ljava lang invoke MethodType Ljava lang i nvoke MethodType Ljava lang invoke MethodHandle Ljava lang invoke MethodT ype Ljava lang invoke CallSite Method arguments 38 V 39 REF_ invokeStatic optjava LambdaExample lambda main 0 V 38 V This output refers to a static factory method called metafactory on the LambdaMetafactory implementation class in java lang invoke This is a BSM that will create the linkage bytecode at runtime if the lambda is ever created The metafactory code takes in a lookup object and the
You must have JavaScript enabled to view digital editions.