关于+=复合运算 // 在C#与java中, byte b=100; b=b+100; 编译通不过(类型转换造成),而 byte b=100; b+=100; 能编译通过, 能否给出详细解释。 还请高手赐教。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 b+=100就相当于b = (byte)(b+100)我知道这等于没说还是等高手赐教。 这类题目,反编译一下就可以找到答案了对下面的类进行反编译public class test{ public static void main(String args[]){ byte a = 30; a +=40; int b = 20; b = b+41; }}得到C:\java>javap -c testCompiled from "test.java"public class test extends java.lang.Object{public test(); Code: 0: aload_0 1: invokespecial #1; //Method java/lang/Object."<init>":()V 4: returnpublic static void main(java.lang.String[]); Code: 0: bipush 30 2: istore_1 3: iload_1 4: bipush 40 6: iadd 7: i2b 8: istore_1 9: bipush 20 11: istore_2 12: iload_2 13: bipush 41 15: iadd 16: istore_2 17: return}由此可得出结论:b=b+100; 中,由于b+100后值已提升为int型,再赋给byte型当然不行b+=100; 中,由反编译结果可以看出b+=100相当于b=(byte)(b+100) 楼上正确,右侧有无小数点数字的运算,都会被提升为int类型 不好意思,楼上的两位大哥,小弟皮肤太好,人称··小白…… 反编译,我一点也不明白,能给稍微讲1下吗 ? Code: 0: bipush 30 2: istore_1 3: iload_1 4: bipush 40 6: iadd 7: i2b 8: istore_1 9: bipush 20 11: istore_2 12: iload_2 13: bipush 41 15: iadd 16: istore_2 17: return 这是什么语言?我不懂 这个是为了能够在不同的系统上移植,JAVA自定义的一套代码啦 有个叫作《JAVA虚拟机规范》的书可以看一下吧 求XStream解析有嵌套bean的方案? 哎,无语了,复习看自加,自减的问题,晕了 反射问题 java抽奖器(着急) 关于JAVA窗口编程 线程老是出错 郁闷死了 没有分拉,,,问一个socket的问题 谁有jprobe3.0的crack? 那里有Solaris的中文资料可以下载? java调用方法选择机制 如何提高效率开发 问个关于自省的问题
我知道这等于没说
还是等高手赐教。
public static void main(String args[]){
byte a = 30;
a +=40;
int b = 20;
b = b+41;
}
}得到C:\java>javap -c test
Compiled from "test.java"
public class test extends java.lang.Object{
public test();
Code:
0: aload_0
1: invokespecial #1; //Method java/lang/Object."<init>":()V
4: returnpublic static void main(java.lang.String[]);
Code:
0: bipush 30
2: istore_1
3: iload_1
4: bipush 40
6: iadd
7: i2b
8: istore_1
9: bipush 20
11: istore_2
12: iload_2
13: bipush 41
15: iadd
16: istore_2
17: return}由此可得出结论:
b=b+100; 中,由于b+100后值已提升为int型,再赋给byte型当然不行
b+=100; 中,由反编译结果可以看出b+=100相当于b=(byte)(b+100)
反编译,我一点也不明白,能给稍微讲1下吗 ?
Code:
0: bipush 30
2: istore_1
3: iload_1
4: bipush 40
6: iadd
7: i2b
8: istore_1
9: bipush 20
11: istore_2
12: iload_2
13: bipush 41
15: iadd
16: istore_2
17: return
这是什么语言?我不懂