不可序列化匿名类上的异常
2022-09-03 04:12:02
我有一个用于过滤项目的界面:
public interface KeyValFilter extends Serializable {
public static final long serialVersionUID = 7069537470113689475L;
public boolean acceptKey(String iKey, Iterable<String> iValues);
public boolean acceptValue(String iKey, String value);
}
和包含 类型成员的类。KeyValFilter
public class KeyValFilterCollector extends KeyValCollectorSkeleton {
private static final long serialVersionUID = -3364382369044221888L;
KeyValFilter filter;
public KeyValFilterCollector(KeyValFilter filter) {
this.filter=filter;
}
}
当我尝试用一个匿名类实现来启动时:KeyValFilterCollector
KeyValFilter
new KeyValFilterCollector(new KeyValFilter() {
private static final long serialVersionUID = 7069537470113689475L;
public boolean acceptKey(String iKey, Iterable<String> iValues) {
for (String value : iValues) {
if (value.startsWith("1:"))
return true;
}
return false;
}
public boolean acceptValue(String iKey, String value) {
return value.startsWith("0:");
}
});
我得到一个例外:.Exception in thread "main" java.io.NotSerializableException
如何使我编写的匿名类可序列化?