Are jfieldID and jmethodID bound to a specific class, or can I use them on subclass objects?

When I calculate the field identifier (or method identifier) ​​using env->GetFieldID(superClass, name, descriptor) (or env->GetMethodID(superClass, method, descriptor)), can I use the same identifier for objects of type subClass(which inherits from superClass)?

+4
source share
1 answer

Yes you can, but if the derived class overrides the method, it will introduce a new identifier.

With the help superIDcalculated for the superclass, you will effectively call

obj.super.method()

You can consider it as an analogue of Java.lang.Class.getDeclaredMethod()and Java.lang.Class.getDeclaredFields().

+2
source

All Articles