jfieldID 和 jmethodID 是否绑定到特定的 class 或者我可以在 subclass 对象上使用它们吗?
Are jfieldID and jmethodID bound to the specific class or can I use them on subclass objects?
当我用env->GetFieldID(superClass, name, descriptor
)(或env->GetMethodID(superClass, method, descriptor)
)计算字段ID(或方法ID)时,我可以在subClass
类型的对象(继承来自 superClass
)?
可以,但是如果派生的 class 覆盖了一个方法,它会引入一个新的 ID。
通过为超级 class 计算的 superID
,您将有效地调用
obj.super.method()
您可以将其视为 Java.lang.Class.getDeclaredMethod()
和 Java.lang.Class.getDeclaredFields()
的类比。
当我用env->GetFieldID(superClass, name, descriptor
)(或env->GetMethodID(superClass, method, descriptor)
)计算字段ID(或方法ID)时,我可以在subClass
类型的对象(继承来自 superClass
)?
可以,但是如果派生的 class 覆盖了一个方法,它会引入一个新的 ID。
通过为超级 class 计算的 superID
,您将有效地调用
obj.super.method()
您可以将其视为 Java.lang.Class.getDeclaredMethod()
和 Java.lang.Class.getDeclaredFields()
的类比。