如何将操作码中的ASM API版本映射到Java版本? [英] How do I map ASM's API version in Opcodes to Java version?

查看:113
本文介绍了如何将操作码中的ASM API版本映射到Java版本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ASM 操作码 ASM9 .

ASM's ClassVisitor constructor requires passing one of Opcodes's ASM4, ASM5, ASM6, ASM7, ASM8 or ASM9.

如何知道每个Java版本要使用哪个 ASM#?我将对Java 8使用什么 ASM#?我将在Java 11中使用什么 ASM#?

How do I know which ASM# to use for each version of Java? What ASM# would I use for Java 8? What ASM# would I use for Java 11?

推荐答案

ASM…常数描述了软件所需的最低 ASM库版本.这对于兼容性至关重要,例如在Visitor API中,就像您要覆盖旧版本中不存在的方法一样,当您链接到旧版本时也不会注意到.该方法将永远不会被调用.

The ASM… constants describe the minimum ASM library version required by your software. This is crucial for compatibility, e.g. in the Visitor API, as when you’re overriding a method that does not exist in an older version, you wouldn’t notice when linking against an older version. The method would just never get called.

因此,使用 ASM…常量可以更早地发现此类问题.这就是为什么某些实现类提供不需要版本号,不允许用于子类,而其子类

So, using the ASM… constant allows to spot such issue earlier. That’s why some implementation classes offer a constructors not requiring the version number, not allowed for subclasses, whereas their constructor for subclasses does require it. As only subclasses can override methods, thus, are affected by this issue.

如果您不打算将软件与ASM库的较早版本一起使用,则只需使用与当前ASM库版本相对应的数字即可,即最高版本号,不带 EXPERIMENTAL 后缀.否则,我建议在开发和测试期间使用旧版本,这再次允许只使用该版本中存在的最高 ASM…号.

If you are not planning to use your software with an older version of the ASM library, just use the number corresponding to your current ASM library version, i.e. the highest without the EXPERIMENTAL suffix. Otherwise, I suggest using the older version during development and testing, which again allows to just use the highest ASM… number existing in that version.

您可以使用最新的ASM库来生成针对所有版本的类.这取决于您传递给 V1_8 Java 8和 V11 对于Java 11.这些常量的实际值与

You can use the newest ASM library to generate classes targeting all versions. It depends on the version you’re passing to the visit method. Which is V1_8 for Java 8 and V11 for Java 11. The actual values of these constants are identical to the versions of the JVM specification.

这篇关于如何将操作码中的ASM API版本映射到Java版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆