-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathFoo.java
More file actions
34 lines (27 loc) · 912 Bytes
/
Foo.java
File metadata and controls
34 lines (27 loc) · 912 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// Serializable subclass of nonserializable stateful class - Pages 293-294
package org.effectivejava.examples.chapter11.item74;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
public class Foo extends AbstractFoo implements Serializable {
private void readObject(ObjectInputStream s) throws IOException,
ClassNotFoundException {
s.defaultReadObject();
// Manually deserialize and initialize superclass state
int x = s.readInt();
int y = s.readInt();
initialize(x, y);
}
private void writeObject(ObjectOutputStream s) throws IOException {
s.defaultWriteObject();
// Manually serialize superclass state
s.writeInt(getX());
s.writeInt(getY());
}
// Constructor does not use the fancy mechanism
public Foo(int x, int y) {
super(x, y);
}
private static final long serialVersionUID = 1856835860954L;
}