From c985950989482af485b0a16b479942770bfdcf57 Mon Sep 17 00:00:00 2001 From: Reinier Zwitserloot Date: Thu, 30 Jun 2011 16:34:42 +0200 Subject: Added a note about serialVersionUID and @Synchronized to the feature docs. --- website/features/Synchronized.html | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'website') 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 new Object() as most snippets showing this pattern in action use. Lombok does this because a new object is NOT serializable, but 0-size array is. Therefore, using @Synchronized will not prevent your object from being serialized.

+ Having at least one @Synchronized 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 serialVersionUID changes. We suggest you always add + a serialVersionUID to your classes if you intend to store them long-term via java's serialization mechanism. If you do so, removing + all @Synchronized annotations from your method will not break serialization. +

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 very hard to find bug!

-- cgit