Inspectopedia Help

'@Serial' annotation could be used

Reports methods and fields in the Serializable and Externalizable classes that are suitable to be annotated with the java.io.Serial annotation. The quick-fix adds the annotation.

Example:

class Main implements Serializable { private static final long serialVersionUID = 7874493593505141603L; private void writeObject(ObjectOutputStream out) throws IOException { } }

After the quick-fix is applied:

class Main implements Serializable { @Serial private static final long serialVersionUID = 7874493593505141603L; @Serial private void writeObject(ObjectOutputStream out) throws IOException { } }

Example:

class Main implements Externalizable { protected Object readResolve() throws ObjectStreamException { return "SomeObject"; } }

After the quick-fix is applied:

class Main implements Externalizable { @Serial protected Object readResolve() throws ObjectStreamException { return "SomeObject"; } }

For more information about all possible cases, refer the documentation for java.io.Serial.

This inspection only reports if the language level of the project or module is 14 or higher.

New in 2020.3

Inspection Details

Available in:

IntelliJ IDEA 2023.3, Qodana for JVM 2023.3

Plugin:

Java, 233.SNAPSHOT

Last modified: 13 July 2023