?????????????????Object????????? ??????this?? 99????? invokevirtual #2?????????????setX?? ?????????this??99???this.setX(99)?? ??????????????д??? ????????????????? ???????????SubClass.setX:
????public class bugme.SubClass extends bugme.SuperClass {
????......
????public void setX(int);
????Code:
????0: aload_0
????1: iload_1
????2: invokespecial #3                  // Method bugme/SuperClass.setX:(I)V
????......
????}
??????????????????????????????? ???????this?? ??????????????????? ???99?? invokespecial #3???????????setX?? ????????????д??super.setX(int)
????SuperClass.setX?????:
????public class bugme.SuperClass {
????......
????public void setX(int);
????Code:
????0: aload_0
????1: iload_1
????2: putfield      #3                  // Field mSuperX:I
????5: return
????}
???????????this????? ??????????? putfield #3???????????????????????? ?????mSuperX??????? ???????????????????????this.mSuperX = x;
????????????????????????setX:
public class bugme.SubClass extends bugme.SuperClass {
......
public void setX(int);
Code:
0: aload_0
1: iload_1
2: invokespecial #3                  // Method bugme/SuperClass.setX:(I)V
->5: aload_0                           // ??????????
6: iload_1
7: putfield      #2                  // Field mSubX:I
10: getstatic     #4                  // Field java/lang/System.out:Ljava/io/PrintStream;
13: new           #5                  // class java/lang/StringBuilder
16: dup
17: invokespecial #6                  // Method java/lang/StringBuilder."<init>":()V
20: ldc           #7                  // String SubX is assigned
22: invokevirtual #8                  // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
25: iload_1
26: invokevirtual #9                  // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
29: invokevirtual #10                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
32: invokevirtual #11                 // Method java/io/PrintStream.println:(Ljava/lang/String;)V
35: return
}
??????5??????????????? 5??6??7?????????????mSubX?? ???mSubX??99??? ??????????????????System.out.println("SubX is assigned " + x);??????? ?????????Java????????????StringBuilder???????????? ????????.
???????????? ?????????????????????????????:
????public class bugme.SubClass extends bugme.SuperClass {
????public bugme.SubClass();
????Code:
????0: aload_0
????->1: invokespecial #1                  // Method bugme/SuperClass."<init>":()V
????4: aload_0
????5: iconst_1
????6: putfield      #2                  // Field mSubX:I
????9: return
????......
????}
???????mSubX?????99??? ??????????4??5??6?? ?????????SubClass???????? ??????1????mSubX?? 99??1??????.
????????????? ????????????????????????????:
????public class Main {
????public static void main(String[] args) {
????->SubClass sc = new SubClass();
????sc.printX();
????}
????}
????????????е???????mSubX????? ?????1??.
????????????JVM????????? Dalvik???????????? ???????Java????? ???????smali?? ?????????. ????Android?????????????????? ??????????app???з???smali???? smali???澭??????????v0?? v1???????? ?????????????? ??????????bytecode?? ?????????????????.
???????????
????????????Java??????????????? ??????????????????????. ???縸???????е?????????????? ?????????????????д??? ???????
????????????? ????????????????????? ??????. ??????м????? ??????????. ?????new??????? ?????????????:
????????static??? -> ????static??? -> ??????????????????????? -> ???????? -> ??????????????????????? -> ????????
?????????????е????????setX?? ???mSubX???????????????????? ??????????????????????mSubX??????????飬 ???????????????????? ?????????????.
????Java?У? ????????????????????????е?final?????? ?????final????(?????private???????final)?? ?????????final??? ?????????????????е????.
????????????????? ??????????????bug. ????????????????????? ????????С?????????.
?????????????Java??????(?????) (??е????????? 2012??11?μ?1??) ??8.3.3С????д???? ??????????????????????bug??? ?????????????????.
??????????????е??????????????????? ???????????? ??????Щ????????????? ????????????????????????????. ???????д??????μ????.
????????????????????????????? ???????????drakeet??.
????????
????????????????? ????????д:
????public class SubClass extends SuperClass {
????private int mSubX;
????public SubClass() {}
????......
????}
????????????????????????????setX?? ???????????????????bug??? ?????????????????????????????????????????.
????4: aload_0
????5: iconst_1
????6: putfield      #2                  // Field mSubX:I
??????ν??????????? ?????????????????????????? ???????????????????? ?????汻??????0?? ?????????????.
?????????????仰?? ???Ч??????? ??????????????.
????private int mSubX;
????private int mSubX = 0;
???????????£? ?????????????????κ????(?????????????bug)?? ????????????????????????? ??????????<init>????????????3????? ?????aload_0?? iconst_0?? putfield #**?? ?????????????.
?????????????????????????????????? ?????????????????? ????????3?????.