电脑故障

位置:IT落伍者 >> 电脑故障 >> 浏览文章

Class文件详解 (2)


发布日期:2021/12/26
 

继续分析Class文件的结构

上次读取了constant pool紧接着是这个类或接口的Access flagsJVM定义的关于class或interface的Access flags有

private static short ACC_PUBLIC= x;

private static short ACC_FINAL = x;

private static short ACC_SUPER = x;

private static short ACC_INTERFACE = x;

private static short ACC_ABSTRACT= x;

// read access flags:

short access_flags = inputreadShort();

Systemoutprint(Access flags:);

if((access_flags & ACC_PUBLIC) == ACC_PUBLIC)

Systemoutprint( public);

if((access_flags & ACC_FINAL) == ACC_FINAL)

Systemoutprint( final);

if((access_flags & ACC_SUPER) == ACC_SUPER)

Systemoutprint( super);

if((access_flags & ACC_INTERFACE) == ACC_INTERFACE)

Systemoutprint( interface);

if((access_flags & ACC_ABSTRACT) == ACC_ABSTRACT)

Systemoutprint( abstract);

Systemoutprintln();

然后是this class和super class

// read this class and super class:

short this_class_index = inputreadShort();

short super_class_index = inputreadShort();

Systemoutprintln(This class = + this_class_index);

Systemoutprintln(Super class = + super_class_index);

根据this class的index可以从constant pool中得到这个class的信息super class也一样每个class都有super class只有Object的super class index=

接下来是这个class继承了多少个interface和每个interface在constant pool中的index

// read interfaces count:

short interfaces_count = inputreadShort();

Systemoutprintln(Interfaces count = + interfaces_count);

// read each interface:

for(int i=; i<=interfaces_count; i++) {

short interface_index = inputreadShort();

Systemoutprintln(No + i + interface index = + interface_index);

}

结果如下

Access flags: public final super

This class =

Super class =

Interfaces count =

上一篇:多条问候语句交替显示

下一篇:StarSuite 6.0和SDK安装以及配置指南之二