1

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.

2
  • 2
    What exactly are you trying to inspect? Note in particular that if the Groovy 3 compiler gets off the ground, with its support for Java 8-style lambdas, it's likely to emit significantly different bytecode. Commented Oct 16, 2016 at 2:36
  • openjdk's javac is not the only java compiler in existence, ecj is a commonly used alternative for example. Commented Oct 16, 2016 at 19:24

1 Answer 1

4

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.