一、概念
上一章节讲到了常量池,如下图,常量池之后便是访问标志acess_flags,占2个字节(u2)。
二、例子
编写一个接口。
public interface Test{ public final String userName="ADMIN"; }
编译之后,用javap命令行打开,可看到访问标志Access_flags。
C:\Users\Administrator\Desktop>javap -verbose Test.class Classfile /C:/Users/Administrator/Desktop/Test.class Last modified 2018-5-13; size 164 bytes MD5 checksum 0948ee61f2cbaaf5477f8c3bea7b62ce Compiled from "Test.java" public interface Test minor version: 0 major version: 52 flags: ACC_PUBLIC, ACC_INTERFACE, ACC_ABSTRACT Constant pool: #1 = Class #9 // Test #2 = Class #10 // java/lang/Object #3 = Utf8 userName #4 = Utf8 Ljava/lang/String; #5 = Utf8 ConstantValue #6 = String #11 // ADMIN #7 = Utf8 SourceFile #8 = Utf8 Test.java #9 = Utf8 Test #10 = Utf8 java/lang/Object #11 = Utf8 ADMIN { public static final java.lang.String userName; descriptor: Ljava/lang/String; flags: ACC_PUBLIC, ACC_STATIC, ACC_FINAL ConstantValue: String ADMIN } SourceFile: "Test.java"
- 如上面橙色标记,可知访问标志值为:flags: ACC_PUBLIC, ACC_INTERFACE, ACC_ABSTRACT
打开Test.class的字节文件,访问标志值紧跟在常量池之后的两个字节,
- 如上图,访问标志值为:0x0601 ,上面已经得出flags: ACC_PUBLIC, ACC_INTERFACE, ACC_ABSTRACT ,参照下表可知,ACC_PUBLIC=0x0001
- ,ACC_INTERFACE=0x0200,ACC_ABSTRACT =0x0400 , 访问标志值0x0601 = 0x0001 or 0x0200 0x0400