当将包含5000个Java文件的大型项目从Java ME移植到Java SE时,我尝试将javax.microedition.event.Event替换为我自己的类(EventManager
和EventListener
相同):
public class Event extends java.util.EventObject {
protected String mName;
protected Object mValue;
protected String mMessage;
protected Object mInfo;
public Event(Object source) {
super(source);
}
public Event(String event, String value, String message, Object info) {
super(null); // throws IllegalArgumentException
mName = event;
mValue = value;
mMessage = message;
mInfo = info;
}
不幸的是,基类java.util.EventObject
不喜欢source
为null
。
我已经搜索过,无法找到任何合适的Java源代码。
我的问题是:
如何在此处为构造函数public Event(String event, String value, String message, Object info)
编写替换代码?如何设置source
,从哪里获取它?
答案 0 :(得分:2)
public class Event extends java.util.EventObject {
public static final Object UNKNOWN_SOURCE = new Object();
public Event(String event, String value, String message, Object info) {
super(UNKNOWN_SOURCE);
mName = event;
mValue = value;
mMessage = message;
mInfo = info;
}