有时候当需要远程传送一个LIST<Object>对象的时候会报无法序列化 的错误。解决办法可新建一个如下类:
/**
*
*/
package com.rodrigue.nepo.core.model;
import java.io.Externalizable;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
/**
* @author LEO.ZHOU
* DATE 2009-12-9
*/
public class SerializableList<E> extends ArrayList<E> implements Externalizable{
public SerializableList() {
super();
}
public SerializableList(Collection<? extends E> c) {
super(c);
}
public void readExternal(ObjectInput in) throws IOException,
ClassNotFoundException {
int elementCount = in.readInt();
this.ensureCapacity(elementCount);
for (int i = 0; i < elementCount; i++) {
this.add((E) in.readObject());
}
}
public void writeExternal(ObjectOutput out) throws IOException {
out.writeInt(size());
for (int i = 0; i < size(); i++) {
if (get(i) instanceof Serializable) {
out.writeObject(get(i));
} else {
out.writeObject(null);
}
}
}
}
然后用SerializableList类代替你使用的ArrayList类即可实现远程传输。