如果您尝试从您的类生成回调(引发事件):
在生成回调的类中:
public interface EventHappened{
void callback(int arg1, String arg2);
}
...
ArrayList<EventHappened> eventHappenedObservers = new ArrayList<~>;
...
public void setEventHappenedObserver(EventHappened observer){
eventHappenedObservers.add(observer);
}
...
if (eventHasHappened){
for (EventHappened eventHappenedObserver:eventHappenedObservers){
eventHappendedObserver.callback(event.number,event.toString());
}
}
...
在消费类中:
instanceOfClassRaisingCallback.setEventHappendedObserver(new EventHappened{
@Override
void callBack(int arg1, String arg2){
doStuffWithArgs(arg1,arg2);
}
)};
(从记忆中,为拼写错误和语法错误道歉,但你明白了......我希望)
祝你好运。