⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 abstractnestedcircularreferencetest.java

📁 xstream是一个把java object序列化成xml文件的开源库,轻便好用
💻 JAVA
字号:
package com.thoughtworks.acceptance;import java.io.Serializable;import java.io.ObjectInputStream;import java.io.IOException;import java.io.ObjectOutputStream;public abstract class AbstractNestedCircularReferenceTest extends AbstractAcceptanceTest {    public static class WeirdThing implements Serializable {        public transient Object anotherObject;        private NestedThing nestedThing = new NestedThing();        private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {            in.defaultReadObject();            anotherObject = in.readObject();        }        private void writeObject(ObjectOutputStream out) throws IOException {            out.defaultWriteObject();            out.writeObject(anotherObject);        }        private class NestedThing implements Serializable {            private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {                in.defaultReadObject();            }            private void writeObject(ObjectOutputStream out) throws IOException {                out.defaultWriteObject();            }        }    }    public void testWeirdCircularReference() {        // I cannot fully explain what's special about WeirdThing, however without ensuring that a reference is only        // put in the references map once, this fails.        // This case was first noticed when serializing JComboBox, deserializing it and then serializing it again.        // Upon the second serialization, it would cause the Sun 1.4.1 JVM to crash:        // Object in = new javax.swing.JComboBox();        // Object out = xstream.fromXML(xstream.toXML(in));        // xstream.toXML(out); ....causes JVM crash on 1.4.1        // WeirdThing is the least possible code I can create to reproduce the problem.        // setup        WeirdThing in = new WeirdThing();        in.anotherObject = in;        // execute        WeirdThing out = (WeirdThing) xstream.fromXML(xstream.toXML(in));        // verify        assertSame(out, out.anotherObject);    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -