17
17
* <p>
18
18
* The class can be used as an argument or return type for serialization-based RPC technologies like RMI.
19
19
* <p>
20
- * There are three ways to use this class to serialize instances which have an optional attribute .
20
+ * There are three ways to use this class to serialize instances which have an optional field .
21
21
* <p>
22
- * <h2>Transform On Serialization</h2> The attribute can be declared as {@code transient Optional<T> optionalAttribute },
22
+ * <h2>Transform On Serialization</h2> The field can be declared as {@code transient Optional<T> optionalField },
23
23
* which will exclude it from serialization.
24
24
* <p>
25
25
* The class then needs to implement custom (de)serialization methods {@code writeObject} and {@code readObject}. They
26
- * must transform the {@code optionalAttribute } to a {@code SerializableOptional} when writing the object and after
26
+ * must transform the {@code optionalField } to a {@code SerializableOptional} when writing the object and after
27
27
* reading such an instance transform it back to an {@code Optional}.
28
28
* <p>
29
29
* <h3>Code Example</h3>
32
32
* private void writeObject(ObjectOutputStream out) throws IOException {
33
33
* out.defaultWriteObject();
34
34
* out.writeObject(
35
- * SerializableOptional.fromOptional(optionalAttribute ));
35
+ * SerializableOptional.fromOptional(optionalField ));
36
36
* }
37
37
*
38
38
* private void readObject(ObjectInputStream in)
39
39
* throws IOException, ClassNotFoundException {
40
40
*
41
41
* in.defaultReadObject();
42
- * optionalAttribute =
42
+ * optionalField =
43
43
* ((SerializableOptional<T>) in.readObject()).toOptional();
44
44
* }
45
45
* </pre>
46
46
* <p>
47
47
* <h2>Transform On Replace</h2> If the class is serialized using the Serialization Proxy Pattern (see <i>Effective
48
48
* Java</i> by Joshua Bloch, Item 78), the proxy can have an instance of {@link SerializableOptional} to clearly denote
49
- * the attribute as being optional.
49
+ * the field as being optional.
50
50
* <p>
51
51
* In this case, the proxy needs to transform the {@code Optional} to {@code SerializableOptional} in its constructor
52
52
* (using {@link SerializableOptional#fromOptional(Optional)}) and the other way in {@code readResolve()} (with
53
53
* {@link SerializableOptional#asOptional()}).
54
54
* <p>
55
- * <h2>Transform On Access</h2> The attribute can be declared as {@code SerializableOptional<T> optionalAttribute }. This
55
+ * <h2>Transform On Access</h2> The field can be declared as {@code SerializableOptional<T> optionalField }. This
56
56
* will include it in the (de)serialization process so it does not need to be customized.
57
57
* <p>
58
- * But methods interacting with the attribute need to get an {@code Optional} instead. This can easily be done by
59
- * writing the accessor methods such that they transform the attribute on each access.
58
+ * But methods interacting with the field need to get an {@code Optional} instead. This can easily be done by writing
59
+ * the accessor methods such that they transform the field on each access.
60
60
* <p>
61
61
* Note that {@link #asOptional()} simply returns the {@code Optional} which with this instance was created so no
62
62
* constructor needs to be invoked.
63
63
* <p>
64
- * <h3>Code Example</h3> Note that it is rarely useful to expose an optional attribute via accessor methods. Hence the
64
+ * <h3>Code Example</h3> Note that it is rarely useful to expose an optional field via accessor methods. Hence the
65
65
* following are private and for use inside the class.
66
66
*
67
67
* <pre>
68
- * private Optional<T> getOptionalAttribute () {
69
- * return optionalAttribute .asOptional();
68
+ * private Optional<T> getOptionalField () {
69
+ * return optionalField .asOptional();
70
70
* }
71
71
*
72
- * private void setOptionalAttribute (Optional<T> optionalAttribute ) {
73
- * this.optionalAttribute = SerializableOptional.fromOptional(optionalAttribute );
72
+ * private void setOptionalField (Optional<T> optionalField ) {
73
+ * this.optionalField = SerializableOptional.fromOptional(optionalField );
74
74
* }
75
75
* </pre>
76
76
*
@@ -85,8 +85,7 @@ public final class SerializableOptional<T extends Serializable> implements Seria
85
85
private static final long serialVersionUID = -652697447004597911L ;
86
86
87
87
/**
88
- * The wrapped {@link Optional}. Note that this attribute is transient so it will not be (de)serializd
89
- * automatically.
88
+ * The wrapped {@link Optional}. Note that this field is transient so it will not be (de)serializd automatically.
90
89
*/
91
90
private final Optional <T > optional ;
92
91
0 commit comments