package com.test.event.listener;
import java.util.EventListener;
public interface NotifyListener extends EventListener {
String notify(String message);
}
package com.test.event.listener;
public class ProcData {
private NotifyListener listener;
public void addListener(NotifyListener notifyListener) {
this.listener = notifyListener;
}
public void send() {
for (int i = 0; i < 10; i++) {
String message= listener.notify("open the door");
System.out.println(message);
}
}
}
package com.test.event.listener;
public class ProcessRepeatData {
public static void test() {
ProcData importData = new ProcData();
importData.addListener(new NotifyListener() {
@Override
public String notify(String message) {
System.out.println("====== result: " + message);
return "notify";
}
});
importData.send();
}
public static void main(String args[]) {
test();
}
}