Search code examples
javajava-8bytecodejava-bytecode-asm

Java 8 lambda expression bytecode consistency


I've been digging through Java lambda expression bytecode as compiled by my OpenJDK compiler, and I'm wondering, can lambda expression bytecode vary by compiler/runtime? I'd like to know that my inspection logic will work across platforms, or not.


Solution

  • can lambda expression bytecode vary by compiler/runtime?

    In theory yes. The JLS does NOT specify that particular bytecodes / sequences must be generated.

    You would need to check the bytecodes emitted by existing Java 8 & Java 9 compilers to see how much they differ. (And that doesn't tell you about compilers / versions that are yet to be written!)

    I'd like to know that my inspection logic will work across platforms, or not.

    The solution should be to build a comprehensive set of test cases and run them against the code produced by all Java compilers that you want to support.

    In short: test it.