主函数:
public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.layout_main); B b = new B(); b.bMothed(); } }
接口:
public interface Callback { void print(String s); }
Class A
public class A { public void mothed(Callback callback) { callback.print("callback A"); } }
Class B
public class B implements Callback{ public void bMothed() { A a = new A(); a.mothed(this); } @Override public void print(String s) { Log.e("i am B",s); } }