简体   繁体   English

Java 8 lambda 表达式字节码一致性

[英]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?我一直在挖掘由我的 OpenJDK 编译器编译的 Java lambda 表达式字节码,我想知道,lambda 表达式字节码是否会因编译器/运行时而异? I'd like to know that my inspection logic will work across platforms, or not.我想知道我的检查逻辑是否可以跨平台工作。

can lambda expression bytecode vary by compiler/runtime? lambda 表达式字节码可以因编译器/运行时而异吗?

In theory yes.理论上是的。 The JLS does NOT specify that particular bytecodes / sequences must be generated. JLS 没有指定必须生成特定的字节码/序列。

You would need to check the bytecodes emitted by existing Java 8 & Java 9 compilers to see how much they differ.您需要检查现有 Java 8 和 Java 9 编译器发出的字节码,看看它们有多少不同。 (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.解决方案应该是构建一组全面的测试用例,并针对您想要支持的所有 Java 编译器生成的代码运行它们。

In short: test it.简而言之:测试它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM