Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IntelliJ IDEA generating serialVersionUID

How do generate this value in IntelliJ IDEA?

I go to Settings -> Errors -> Serialization issues -> Serializable class without ‘serialVersionUID’, but it still doesn't show me the warning. My class PKladrBuilding parent implements interface Serializable.

Part of the code:

public class PKladrBuilding extends PRQObject  public abstract class PRQObject extends PObject  public abstract class PObject implements Serializable 
like image 788
Kirill Bazarov Avatar asked Oct 16 '12 10:10

Kirill Bazarov


People also ask

How do I generate Serializable in IntelliJ?

You can generate SerialVersionUID in intellij by pressing ctrl + shift +A (find action) and then typing Serializable class without serialVersionUID and toggle it from Off to On.

How do I give serialVersionUID?

File -> Settings -> Editor -> Inspections -> Java -> Serialization issues -> Serializable class without 'serialVersionUID' - set flag and click 'OK'. (For Macs, Settings is under IntelliJ IDEA -> Preferences...)

How serialVersionUID is generated when it's not defined in code?

If class does not contain a serialVersionUID field, its serialVersionUID will be automatically generated by the compiler. Different compilers, or different versions of the same compiler, will generate potentially different values.

Where can I find serialVersionUID of a class?

for Android developers, you can also enable serialization inspection from Settings -> Editor -> Inspections -> enable "Serializable class without 'serialVersionUID' check" first, then ALT+ ENTER, the studio will create serialVersionUID for you.


1 Answers

I am not sure if you have an old version of IntelliJ IDEA, but if I go to menu FileSettings...InspectionsSerialization issues → Serializable class without 'serialVersionUID'` enabled, the class you provide give me warnings.

Enter image description here

If I try the first class I see:

Enter image description here

BTW: It didn't show me a warning until I added { } to the end of each class to fix the compile error.

like image 74
Peter Lawrey Avatar answered Nov 01 '22 19:11

Peter Lawrey