我有一个java类,它触发自定义java事件.代码的结构如下:
public class AEvent extends EventObject {
...
}
public interface AListener extends EventListener {
public void event1(AEvent event);
}
public class A {
public synchronized void addAListener(AListener l) {
..
}
public synchronized void removeAListener(AListener l) {
..
}
protected void fireAListenerEvent1(AEvent event) {
..
}
}
Run Code Online (Sandbox Code Playgroud)
一切正常,但我想创建一个新的A子类(称之为B),它可能会触发一个新事件.我正在考虑以下修改:
public class BEvent extends AEvent {
...
}
public interface BListener extends AListener {
public void event2(BEvent event);
}
public class B extends A {
public synchronized void addBListener(BListener l) { …Run Code Online (Sandbox Code Playgroud)