Java Reference
In-Depth Information
Similarly, the readUnshared() method
reads an “unshared” object from the ObjectInputStream . This method is identical
to readObject , except that it prevents subsequent calls to readObject and read-
Unshared from returning additional references to the deserialized instance obtained
via this call.
Consequently,the writeUnshared() and readUnshared() methodsareunsuitablefor
round-trip serialization of data structures that contain reference cycles.
Consider the following code example:
Click here to view code image
public class Person {
private String name;
Person() {
// Do nothing — needed for serialization
}
Person(String theName) {
name = theName;
}
// Other details not relevant to this example
}
public class Student extends Person implements Serializable {
private Professor tutor;
Student() {
// Do nothing — needed for serialization
}
Student(String theName, Professor theTutor) {
super(theName);
tutor = theTutor;
}
public Professor getTutor() {
return tutor;
}
}
public class Professor extends Person implements Serializable {
Search WWH ::




Custom Search