16 - Java Serialization Versioning - Code Demo 2

preview_player
Показать описание
@backstreetbrogrammer

--------------------------------------------------------------------------------
Chapter 04 - Serialization versioning
--------------------------------------------------------------------------------

It's a good practice to declare a static serialVersionUID variable in every class that implements Serializable.

2. In IntelliJ IDE, we can generate serialVersionUID using the following action:

Ctrl + Shift + A (will launch Actions tab menu) --| type ‘Serializable class without’ and select the item to toggle it on/off.

OR

File --| Settings --| Editor --| Inspections --| Java --| Serialization issues:
Find ‘Serializable class without serialVersionUID’ and check it.

Now, for each class implementing Serializable interface will show warning if no serialVersionUID is declared.

Press “Alt + Enter” and Click on “Create constant field serialVersionUID in …” and serialVersionUID will be generated and declared in the class.

3. OR, we can just declare any random number like 1L or 42L and declare in the class.

For example:
private static final long serialVersionUID = 1L; // 1L or 2L or 3L - any number can be chosen

#java #javadevelopers #javaprogramming #javaserialization
Рекомендации по теме
Комментарии
Автор

good exercise, but how to disable versioning in eclipse

alm
welcome to shbcf.ru