我有这个Java源文件:
import java.util.function.*; public class t { public static void main(String[] args) { Function<Integer,Integer> r = (a) -> a*a+2*a+1; System.out.println(r.apply(2)); } }
我编译它,并且按预期方式工作。这是的输出javap -c -v t,我找不到lambda的位置。Integer每当调用lambda时,告诉jvm使用输入来计算表达式的字节码在哪里?
javap -c -v t
Integer
如果要查看lambda主体的代码a*a+2*a+1,则应调用javap -c -v -p t以查看 私有 方法:
a*a+2*a+1
javap -c -v -p t
private static java.lang.Integer lambda$main$0(java.lang.Integer); descriptor: (Ljava/lang/Integer;)Ljava/lang/Integer; flags: ACC_PRIVATE, ACC_STATIC, ACC_SYNTHETIC Code: stack=3, locals=1, args_size=1 0: aload_0 1: invokevirtual #7 // Method java/lang/Integer.intValue:()I 4: aload_0 5: invokevirtual #7 // Method java/lang/Integer.intValue:()I 8: imul 9: iconst_2 10: aload_0 11: invokevirtual #7 // Method java/lang/Integer.intValue:()I 14: imul 15: iadd 16: iconst_1 17: iadd 18: invokestatic #4 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer; 21: areturn LineNumberTable: line 4: 0