java 常量池结构_Class文件结构-常量池

常量池里存放:

1.字面量(literal)

• 文本字符串

• 声明为final的常量值(final的8种基本类型)

• 非final的基本类型也可能进(doublefloatlong)

2.符号引用(symbolic references)

• 类和接口的全限定名(fully qualified name)

• 字段的名称和描述符(descriptor)

• 方法的名称和描述符

备注:

1. constant_pool_count=1表示常量池中有0个常量项

2. 表的第一个字节表示常量类型(tag)

常量项结构总表

3d1f915bed5748716508dcdc304ab74f.png

示例:

package zero.desk.constantpool;

public class constantpool extends c implements a,b{

private string str = "test string";

private final int a = 10;

private final long b = 10;

private final long bb = 100;

private int c = 11;

private float d = 12f;

private float e = 12f;

private double ee = 12f;

private int m;

public int inc() {

return m + 1;

}

}

constant pool:

#1 = methodref #20.#50 // zero/desk/constantpool/c."":()v

#2 = string #51 // test string

#3 = fieldref #19.#52 // zero/desk/constantpool/constantpool.str:ljava/lang/string;

#4 = fieldref #19.#53 // zero/desk/constantpool/constantpool.a:i

#5 = long 10l

#7 = fieldref #19.#54 // zero/desk/constantpool/constantpool.b:j

#8 = long 100l

#10 = fieldref #19.#55 // zero/desk/constantpool/constantpool.bb:j

#11 = fieldref #19.#56 // zero/desk/constantpool/constantpool.c:i

#12 = float 12.0f

#13 = fieldref #19.#57 // zero/desk/constantpool/constantpool.d:f

#14 = fieldref #19.#58 // zero/desk/constantpool/constantpool.e:f

#15 = double 12.0d

#17 = fieldref #19.#59 // zero/desk/constantpool/constantpool.ee:d

#18 = fieldref #19.#60 // zero/desk/constantpool/constantpool.m:i

#19 = class #61 // zero/desk/constantpool/constantpool

#20 = class #62 // zero/desk/constantpool/c

#21 = class #63 // zero/desk/constantpool/a

#22 = class #64 // zero/desk/constantpool/b

#23 = utf8 str

#24 = utf8 ljava/lang/string;

#25 = utf8 a

#26 = utf8 i

#27 = utf8 constantvalue

#28 = integer 10

#29 = utf8 b

#30 = utf8 j

#31 = utf8 bb

#32 = utf8 c

#33 = utf8 d

#34 = utf8 f

#35 = utf8 e

#36 = utf8 ee

#37 = utf8 d

#38 = utf8 m

#39 = utf8

#40 = utf8 ()v

#41 = utf8 code

#42 = utf8 linenumbertable

#43 = utf8 localvariabletable

#44 = utf8 this

#45 = utf8 lzero/desk/constantpool/constantpool;

#46 = utf8 inc

#47 = utf8 ()i

#48 = utf8 sourcefile

#49 = utf8 constantpool.java

#50 = nameandtype #39:#40 // "":()v

#51 = utf8 test string

#52 = nameandtype #23:#24 // str:ljava/lang/string;

#53 = nameandtype #25:#26 // a:i

#54 = nameandtype #29:#30 // b:j

#55 = nameandtype #31:#30 // bb:j

#56 = nameandtype #32:#26 // c:i

#57 = nameandtype #33:#34 // d:f

#58 = nameandtype #35:#34 // e:f

#59 = nameandtype #36:#37 // ee:d

#60 = nameandtype #38:#26 // m:i

#61 = utf8 zero/desk/constantpool/constantpool

#62 = utf8 zero/desk/constantpool/c

#63 = utf8 zero/desk/constantpool/a

#64 = utf8 zero/desk/constantpool/b

希望与广大网友互动??

点此进行留言吧!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值