我有一个私人抽象类作为听众。我只能通过反射访问它。我如何实现该类?
public class A {
private abstract class OnWorkListener {
public abstract void onWork(int param);
}
private OnWorkListener mListener;
public A(OnWorkListener listener) {
mListener = listener;
}
public void work() {
// some working
if(mListener != null) {
mListener.onWork(0);
}
}
}
public class B {
private static final String TAG = B.class.getSimpleName();
public B() {
//How to overwrite it?
WorkListener listener = new WorkListener() {
public void onWork(int what) {
Log.d(TAG, "onWork "+what);
}
};
A a = new A(listener);
a.work();
}
}
问题是我无法创建抽象类的实例。我需要先实现它。但我找不到答案。