我正在尝试扩展 Java ArrayList 以支持此示例中描述的事件: http ://www.exampledepot.com/egs/java.util/CustEvent.html
问题是 java 在以下行中报告“无法对非静态类型 MyEvent 进行静态引用”:
public interface MyEventListener extends EventListener {
public void myEventOccurred(MyEvent evt);
}
我认为这与泛型有关,但我真的不知道如何解决这个问题。有人可以帮助我吗?
这是我正在尝试做的全部来源:
public class ArrayList<E> extends java.util.ArrayList<E> {
private static final long serialVersionUID = 1L;
// Declare the event. It must extend EventObject.
public class MyEvent extends EventObject {
private static final long serialVersionUID = 1L;
public MyEvent(Object source) {
super(source);
}
}
// Declare the listener class. It must extend EventListener.
// A class must implement this interface to get MyEvents.
public interface MyEventListener extends EventListener {
public void myEventOccurred(MyEvent evt); //Error occurs here
}
}