Notes -Java underlying field table collection

    Table field (field_info) used to describe the remainder of the variables in the interface or class. Field (field) comprises a class instance variables and class variables stage, but not in the interior of the method the remaining local variables. We can think about is described in Java in a field may contain what information? Information may be included are: Scope field (public, private, protected modifier), is an instance variable or class variable (static modifier), the variability (Final), concurrent visibility (volatile modifier, whether to force from the main memory read and write), can be serialized (transient modifier), field data type (basic type, object, array), the field name. These information, each modifier is a Boolean value, or have a modifier or not, it is suitable for use flags to represent. The field name, please, why the field is defined data types, which are not fixed, the constant references to the constant pool can only be described. The final table lists the format field of Table 6-8.

    Access_flags modifiers in the project field, it access_flags item class are very similar, and u2 is a data type, and wherein the meaning of the flag can be provided in Table 6-9.

    Obviously, in reality, ACC_PUBLIC, ACC_PRIVATE, ACC_PROTECTED three flags can only choose one, ACC_FINAL, ACC_VOLATILE can not be selected at the same time. Among the interfaces field must have ACC_PUBLIC, ACC_STATIC, ACC_FINAL signs, which are determined by the rules of the Java language itself.

    Follow signs access_flag are two index values: name_index and descriptor_index. They are the role of the constant pool, representing the simple names of the columns and methods and descriptors. Now we need to explain the "simple name", "descriptor" and the concept appeared several times in front of "fully qualified name" of these three special strings.

   全限定名和简单名称很好理解,以代码清单6-1中的代码为例,“org/fenixsoft/clazz/TestClass”是这个类的全限定名,仅仅是把类全名中的“.”替换成了“/”而已,为了使连续的逗哥全限定名之间不产生混淆,在使用时最后一般会加入一个“;”表示全限定名结束。简单名称是指没有类型和参数修饰的方法或者字段名称,这个类中的inc()和m字段的简单名称分别是“inc”和“m”。

   相对于全限定名和简单名称来说,方法和字段的描述符就要复杂一些。描述符的作用是用来描述字段的数据类型、方法的参数列表(包括数量、类型以及顺序)和返回值根据描述符规则,基本数据类型(byte、char、double、float、int、short、boolean)以及代表无返回值的void类型都用一个大写字符来表示,而对象类型则用字符L加对象的全限定名来表示,详见表6-10.

    对于素组类型,每一维度将使用一个前置的“[”字符来描述,如一个定义为“java.lang.String[][]”类型的二位数组,将被记录为:“”“”“[[Ljava/lang/String;”,一个整数数组“int[]”将被记录为“[I”。

   用描述符来描述方法时,按照先参数列表,后返回值的顺序描述,参数列表按照参数的严格顺序放在一组小括号“()”之内。如方法void inc()的描述符为“()V”,方法 java.lang.String.toString()的描述符为"()Ljava/lang/String;",方法int indexOf(char[]source,int sourceOffset,int sourceCount,char[]target,int targetOffset,int targetCount,int formIndex)的描述符为“([CII[CIII)I”。

字段表集合中不会列出从超类或者父接口中继承而来的字段,但有可能列出原本Java代码之中不存在的字段,碧如在内部类中为了保持对外部类的访问性,会自动添加指向外部类实例的字段。另外在Java语言中字段是无法重载的,两个字段的数据类型、修饰符不管是否相同,都必须使用不一样的名称,但是对于字节码来讲,如果两个字段的描述不一致,那字段重名就是合法的。

 

    

 

Guess you like

Origin blog.csdn.net/helianus/article/details/91980020