50,527
社区成员
发帖
与我相关
我的任务
分享
public class Test {
public static void main(String[] args){
int i = 1;
short s = 2;
char c = 3;
}
}
这三个变量在栈里其实都栈一个int大小。反编译之后用jad处理一下,得到的代码是:
boolean flag = true;
byte byte0 = 2;
byte byte1 = 3;
没能准确地恢复类型信息,只是根据值的范围猜的……
而对象,因为涉及对象布局、垃圾回收、线程状态、多态调用等信息,会关联相应的Class对象,即“类型”信息。 char a = 0x8000; // 1000 0000 0000 0000
short s = (short)0x8000; // 1000 0000 0000 0000
int i1 = a;
int i2 = s;
看其字节码:
0: ldc #2 // int 32768
2: istore_1
3: sipush -32768
6: istore_2
7: iload_1
8: istore_3
9: iload_2
10: istore 4
12: return
32768直接当作int处理了。
sipush指令则会进行sign-extended,具体参考jvms上的指令说明。