diff options
-rw-r--r-- | website/features/Synchronized.html | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/website/features/Synchronized.html b/website/features/Synchronized.html index 69d9dcee..73622e3d 100644 --- a/website/features/Synchronized.html +++ b/website/features/Synchronized.html @@ -48,6 +48,11 @@ just a <code>new Object()</code> as most snippets showing this pattern in action use. Lombok does this because a new object is <em>NOT</em> serializable, but 0-size array is. Therefore, using <code>@Synchronized</code> will not prevent your object from being serialized. </p><p> + Having at least one <code>@Synchronized</code> method in your class means there will be a lock field, but if you later remove all such methods, + there will no longer be a lock field. That means your predetermined <code>serialVersionUID</code> changes. We suggest you <em>always</em> add + a <code>serialVersionUID</code> to your classes if you intend to store them long-term via java's serialization mechanism. If you do so, removing + all <code>@Synchronized</code> annotations from your method will not break serialization. + </p><p> If you'd like to know why a field is not automatically generated when you choose your own name for the lock object: Because otherwise making a typo in the field name will result in a <em>very</em> hard to find bug! </p> |