我正在创建一个用于 Dalvik 应用程序后处理的工具。对于测试,我想创建包含每个操作码的代码。我在理解 const-class 和 const-method-type 操作码的作用时遇到了问题。 dalvik 官方文档中的定义并没有为我阐明这个问题。
const-class
Move a reference to the class specified by the given index into the specified register. In the case where the indicated type is primitive, this will store a reference to the primitive type's degenerate class.
类的引用是什么?据我所知,这不是对对象的引用。
同理
const-method-type
Move a reference to the method prototype specified by the given index into the specified register.
据我了解,这不是函数指针。函数指针由
处理const-method-handle
Move a reference to the method handle specified by the given index into the specified register.
我的问题是:
const-class 和 const-method-type 有什么用?什么样的 Java 代码会在 Dalvik 中生成这些操作码?
也许值得一提的是我的 Java 经验很低 - 我是 C++ 类型的人。
最佳答案
const-class
可以在您引用对象的类属性时生成。例如Class cls = MyObject.class
。
据我所知,方法句柄和类型不是由 Java 代码生成的。您可以使用反射来引用它们,但我认为这样做实际上不会生成 const-method-type
或 const-method-handle
指令
它们支持 invoke-custom
的转换,它主要供其他语言使用,这些语言被编译为 java 字节码并最终编译为 dalvik 字节码。
关于java - 什么是 const-class 和 const-method-type 操作码?什么java代码生成它们?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53831599/