-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathNonSerializableField.java
More file actions
27 lines (25 loc) · 1.12 KB
/
NonSerializableField.java
File metadata and controls
27 lines (25 loc) · 1.12 KB
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
class DerivedFactors { // Class that contains derived values computed from entries in a
private Number efficiency; // performance record
private Number costPerItem;
private Number profitPerItem;
...
}
class WrongPerformanceRecord implements Serializable {
private String unitId;
private Number dailyThroughput;
private Number dailyCost;
private DerivedFactors factors; // BAD: 'DerivedFactors' is not serializable
// but is in a serializable class. This
// causes a 'java.io.NotSerializableException'
// when 'WrongPerformanceRecord' is serialized.
...
}
class PerformanceRecord implements Serializable {
private String unitId;
private Number dailyThroughput;
private Number dailyCost;
transient private DerivedFactors factors; // GOOD: 'DerivedFactors' is declared
// 'transient' so it does not contribute to the
// serializable state of 'PerformanceRecord'.
...
}