第二个测试:
public class Test {
private static byte x;
private static int y;
public static void main(String[] args) {
x = 2; y = 3;
x += y;
x = 2; y = 3;
x = (byte) (x + y);
}
}
对应的底层代码为:
// Method descriptor #10 ()V
// Stack: 1, Locals: 1
public Test();
0 aload_0 [this]
1 invokespecial java.lang.Object() [12]
4 return
Line numbers:
[pc: 0, line: 1]
Local variable table:
[pc: 0, pc: 5] local: this index: 0 type: Test
// Method descriptor #19 ([Ljava/lang/String;)V
// Stack: 2, Locals: 1
public static void main(java.lang.String[] args);
0 iconst_2
1 putstatic Test.x : byte [20]
4 iconst_3
5 putstatic Test.y : int [22]
8 getstatic Test.x : byte [20]
11 getstatic Test.y : int [22]
14 iadd
15 i2b
16 putstatic Test.x : byte [20]
19 iconst_2
20 putstatic Test.x : byte [20]
23 iconst_3
24 putstatic Test.y : int [22]
27 getstatic Test.x : byte [20]
30 getstatic Test.y : int [22]
33 iadd
34 i2b
35 putstatic Test.x : byte [20]
38 return
Line numbers:
[pc: 0, line: 5]
[pc: 8, line: 6]
[pc: 19, line: 7]
[pc: 27, line: 8]
[pc: 38, line: 9]
Local variable table:
[pc: 0, pc: 39] local: args index: 0 type: java.lang.String[]
}
效果也是一致!
就我的理解他们的差别也只是在语法表现上而已!
语法通不过当然无法编译通过,但是底层实际效果我想他们没有差别!
以上纯属个人理解,也没有什么理论根据,只是实验结果!
public class Test {
private static byte x;
private static int y;
public static void main(String[] args) {
x = 2; y = 3;
x += y;
x = 2; y = 3;
x = (byte) (x + y);
}
}
对应的底层代码为:
// Method descriptor #10 ()V
// Stack: 1, Locals: 1
public Test();
0 aload_0 [this]
1 invokespecial java.lang.Object() [12]
4 return
Line numbers:
[pc: 0, line: 1]
Local variable table:
[pc: 0, pc: 5] local: this index: 0 type: Test
// Method descriptor #19 ([Ljava/lang/String;)V
// Stack: 2, Locals: 1
public static void main(java.lang.String[] args);
0 iconst_2
1 putstatic Test.x : byte [20]
4 iconst_3
5 putstatic Test.y : int [22]
8 getstatic Test.x : byte [20]
11 getstatic Test.y : int [22]
14 iadd
15 i2b
16 putstatic Test.x : byte [20]
19 iconst_2
20 putstatic Test.x : byte [20]
23 iconst_3
24 putstatic Test.y : int [22]
27 getstatic Test.x : byte [20]
30 getstatic Test.y : int [22]
33 iadd
34 i2b
35 putstatic Test.x : byte [20]
38 return
Line numbers:
[pc: 0, line: 5]
[pc: 8, line: 6]
[pc: 19, line: 7]
[pc: 27, line: 8]
[pc: 38, line: 9]
Local variable table:
[pc: 0, pc: 39] local: args index: 0 type: java.lang.String[]
}
效果也是一致!
就我的理解他们的差别也只是在语法表现上而已!
语法通不过当然无法编译通过,但是底层实际效果我想他们没有差别!
以上纯属个人理解,也没有什么理论根据,只是实验结果!
我渴望掌控时空的核心——用最先进的技术,打造无比美丽的世界!