迷茫2017-04-17 17:04:213楼
Compiled from "MainActivity.java"
class top.ffish.myapp.MainActivity$1 implements android.view.View$OnClickListener {
final top.ffish.myapp.MainActivity this$0;
top.ffish.myapp.MainActivity$1(top.ffish.myapp.MainActivity);
Code:
0: aload_0
1: aload_1
2: putfield #1 // Field this$0:Ltop/ffish/myapp/MainActivity;
5: aload_0
6: invokespecial #2 // Method java/lang/Object."":()V
9: return
public void onClick(android.view.View);
Code:
0: new #3 // class android/content/Intent
3: dup
4: invokespecial #4 // Method android/content/Intent."":()V
7: astore_2
8: aload_0
9: getfield #1 // Field this$0:Ltop/ffish/myapp/MainActivity;
12: aload_2
13: invokevirtual #5 // Method top/ffish/myapp/MainActivity.startActivity:(Landroid/content/Intent;)V
16: return
}
如果你反编译MainActivity$1.class,可以看到这个内部类有一个this$0变量引用MainActivity对象。这个变量在构造器中被初始化(2: putfield指令)
也就是说,你不用显示的写MainActivity.this.startActivity(),编译器帮你把这工作给做了