Does java.lang.reflect.Field#slot
hold a sequence number in the order how fields were declared in the source file?
I know its private and I should not use it and stuff but anyway...
Field.slot
meaning is implementation defined. In HotSpot JVM it contains the index into the VM's internal field array for the given class. slot
field is set inside JVM runtime when a Field
object is created, see reflection.cpp.
This index does not necessarily match the order of the fields in Java source file. It is neither related to the offset of the field from the object header. It is better not to make any assumptions about the meaning of slot
. The key meaning is to allow JVM to quickly map a java.lang.reflect.Field
object to the internal Field representation in Metaspace.