我正在运行 guava-14.0.1 并且我有以下代码:
public class LinearClsMalletAdaptor extends Classifier implements Serializable{
private BiMap<Double, String> indexToLabel;
.........
classifier = new LinearClsMalletAdaptor(sp, model, hashBiMap.inverse());
分类器是我希望保留的对象,我在 Mac 上对其进行序列化和反序列化没有问题。
但是,使用我发给我朋友的同一个序列化文件,他在反序列化过程中在 Windows 机器上遇到了以下问题:
java.lang.ClassCastException: com.google.common.collect.HashBiMap cannot be cast to
com.google.common.collect.AbstractBiMap
at com.google.common.collect.AbstractBiMap$Inverse.readObject(AbstractBiMap.java:390)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at java.io.ObjectStreamClass.invokeReadObject(ObjectStreamClass.java:969)
at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1848)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1752)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1328)
at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1946)
at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1870)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1752)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1328)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:350)
at java.util.HashMap.readObject(HashMap.java:1030)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at java.io.ObjectStreamClass.invokeReadObject(ObjectStreamClass.java:969)
at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1848)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1752)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1328)
at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1946)
at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1870)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1752)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1328)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:350)
at sg.edu.astar.i2r.batc.projects.getme.core.classify.hier.topdown.TopDownClassificationAnnotator.initialize(TopDownClassificationAnnotator.java:63)
at
如果他在自己的机器上执行序列化,则不会出现此问题。我有点困惑,HashBiMap 类是可序列化的吗?api文档说
HashBiMap 及其逆都是可序列化的。
但是这里的讨论似乎有点混乱?