mirror of
https://github.com/tiennm99/lombok.git
synced 2026-10-20 02:17:52 +00:00
Added a note about serialVersionUID and @Synchronized to the feature docs.
This commit is contained in:
1 parent
d5d7922801
commit
c985950989
1 file changed
+5
@@ -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>
|
||||
|
||||
Reference in new issue
Block a user