...
| Code Block | ||
|---|---|---|
| ||
String filename = "serial";
try(ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(filename))) {
// Serializing using writeUnshared
oos.writeUnshared(jane);
} catch (Exception e) {
//handle Handle error
}
// Deserializing using readUnshared
try(ObjectInputStream ois = new ObjectInputStream(new FileInputStream(filename))){
Professor jane2 = (Professor)ois.readUnshared();
System.out.println("checkTutees returns: " +
jane2.checkTutees());
} catch (Exception e) {
//handle Handle error
} |
Compliant Solution
...
| Code Block | ||
|---|---|---|
| ||
String filename = "serial";
try(ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(filename))) {
// Serializing using writeUnshared
oos.writeObject(jane);
} catch (Exception e) {
//handle Handle error
}
// Deserializing using readUnshared
try(ObjectInputStream ois = new ObjectInputStream(new FileInputStream(filename))) {
Professor jane2 = (Professor)ois.readObject();
System.out.println("checkTutees returns: " +
jane2.checkTutees());
} catch (Exception e) {
//handle Handle error
} |
Applicability
Using the writeUnshared() and readUnshared() methods may produce unexpected results.
...