我得到java.io.NotSerializableException:java.util.ArrayList $ SubList以获取以下代码.
ObjectInputStream os=new ObjectInputStream(new FileInputStream("AllEMExampleObjects.dat"));
Set<EntitiyMentionExample> AllEMs=(Set<EntitiyMentionExample>)(os.readObject());
EntitiyMentionExample[] AllExamples=AllEMs.toArray(new EntitiyMentionExample[0]);
ObjectOutputStream oo=new ObjectOutputStream(new FileOutputStream("C:\\Users\\15232114\\workspace\\Year2\\FormatedExamples\\TestSerialization.dat"));
oo.writeObject(AllExamples[0]);
Run Code Online (Sandbox Code Playgroud)
显然,EntitiyMentionExample类是Serializable,这就是它的Set <>已存储在dat文件(AllEMExampleObjects.dat)中的原因.那为什么现在不存储它的单个实例呢?