-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathTransientNotSerializable.qhelp
More file actions
48 lines (36 loc) · 1.36 KB
/
TransientNotSerializable.qhelp
File metadata and controls
48 lines (36 loc) · 1.36 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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<!DOCTYPE qhelp PUBLIC
"-//Semmle//qhelp//EN"
"qhelp.dtd">
<qhelp>
<overview>
<p>
The <code>transient</code> modifier is used to identify fields that are not part of the persistent state of the class. As such, it only has an
effect if the class is serializable, and has no purpose in a non-serializable class.
</p>
<p>
A field that is marked <code>transient</code> in a non-serializable class is likely to be a leftover from a time when the class
was serializable.
</p>
</overview>
<recommendation>
<p>
If the class is non-serializable, leave out the <code>transient</code> modifier. Otherwise,
use the modifier, and ensure that the class (or a relevant supertype) implements <code>Serializable</code>.
</p>
</recommendation>
<example>
<p>The following example shows two fields that are declared <code>transient</code>. The modifier only has an effect
in the class that implements <code>Serializable</code>.</p>
<sample src="TransientNotSerializable.java" />
</example>
<references>
<li>
Java Language Specification, 3rd Ed:
<a href="https://docs.oracle.com/javase/specs/jls/se6/html/classes.html#8.3.1.3">8.3.1.3 transient Fields</a>.
</li>
<li>
Java 6 Object Serialization Specification:
<a href="http://docs.oracle.com/javase/6/docs/platform/serialization/spec/serial-arch.html#6250">1.5 Defining Serializable Fields for a Class</a>.
</li>
</references>
</qhelp>