Android D8 编译器 和 R8 工具,【一篇文章搞懂】

android.enableIncrementalDesugaring=false.
android.enableDesugar=false 
2.1 Lambda 表达式

Java 8 中一个重大变更是引入 Lambda 表达式。

public class Lambda {
    public static void main(String[] args) {
        logDebug(msg-> System.out.println(msg), "HelloWorld");
    }

    static void logDebug(Logger logger, String msg) {
        logger.log(msg);
    }

    @FunctionalInterface
    interface Logger {
        void log(String msg);
    }
} 

通过 javac 指令将上面的 Lambda.java 转换为字节码。

$javac Lambda.java 

接下来通过 javap -v 指令查看字节码的详细内容:

dengshiweideMacBook-Pro:Desktop dengshiwei$ javap -v Lambda.class
Classfile /Users/dengshiwei/Desktop/Lambda.class
  Last modified 2019-5-12; size 1120 bytes
  MD5 checksum 67301305720e60d4ef1ff286769768e6
  Compiled from "Lambda.java"
public class Lambda
  minor version: 0
  major version: 52
  flags: ACC_PUBLIC, ACC_SUPER
Constant pool:
   #1 = Methodref          #9.#25         // java/lang/Object."":()V
   #2 = InvokeDynamic      #0:#30         // #0:log:()LLambda$Logger;
   #3 = String             #31            // HelloWorld
   #4 = Methodref          #8.#32         // Lambda.logDebug:(LLambda$Logger;Ljava/lang/String;)V
   #5 = InterfaceMethodref #10.#33        // Lambda$Logger.log:(Ljava/lang/String;)V
   #6 = Fieldref           #34.#35        // java/lang/System.out:Ljava/io/PrintStream;
   #7 =

你可能感兴趣的:(Android,android,java,eclipse,移动开发)