String int类型对应的jvm指令

//ldc 123->astore_1
String a = "123";
//new->dup->ldc 1234->init->astore_2
String b = new String("1234");
//iconst_1->istore_3
int c = 1;
//bipush 100->istore 4
int e = 100;
//sipush 1024->invokestatic(Integer.valueOf)->astore
Integer f = 1024;
//new ->dup->sipush 2048->init->astore
Integer g = new Integer(2048);
//ldc->asotre
String h = Aspect.A;
//iconst_1->istore
int m = Aspect.B;


从代码中可以看出:

1、字符串都会在编译时进入常量池,在使用时直接从常量池压入栈顶,

2、int类型常量会根据大小区分指令,0~5一段,-128~127一段,-32768-32767一段,其余会作为常量放入常量池

3、字符串直接赋值,是直接把常量池地址赋给变量

4、字符串新建是先新建对象,再把对象地址赋给变量
5、引用其他类的常量都会在编译期转换为本类的常量

6、自动装箱是调用Integer.valueOf

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值