About Serializable and serialVersionUID

Serializable

SerialVersionUID

@SuppressWarnings("serial")

Sample with warning

Person.java


package sample;

import java.io.Serializable;

public class Person implements Serializable {
	public String name;

	public SerializablePerson(String name) {
		this.name = name;
	}
}

If you compile with the option (to give all warnings)

javac -Xlint SerializablePerson.java

I get a warning (It may not be displayed on Eclipse depending on the settings (Preferences-> Java-> Compiler-> Error / Warning))

Japanese


Serializable.java:5:warning: [serial]SerialVersionUID is not defined in the serializable class Serializable

English (probably)


The serializable class Mutter does not declare a static final serialVersionUID field of type long

It does not appear when executed with annotations.

Person.java


package sample;

import java.io.Serializable;

@SuppressWarnings("serial")
public class Person implements Serializable {
	public String name;

	public SerializablePerson(String name) {
		this.name = name;
	}
}

reference

What I know about the esoteric Serializable specification, or my understanding Add Star The story of responsibility for inheritance was very helpful

Recommended Posts

About Serializable and serialVersionUID
About Bean and DI
About classes and instances
About gets and gets.chomp
About redirect and forward
About encapsulation and inheritance
About for statement and if statement
About synchronized and Reentrant Lock
About Ruby hashes and symbols
[Java] About String and StringBuilder
About classes and instances (evolution)
About pluck and ids methods
Consideration about classes and instances
About Java Packages and imports
About Ruby and object model
About Ruby classes and instances
About instance variables and attr_ *
About self-introduction and common errors
About C # lambda expressions and Linq
About Java static and non-static methods
About fastqc of Biocontainers and Java
Learn more about gems and bundlers
About the equals () and hashcode () methods
About Ruby single quotes and double quotes
About Gradle's setup phase and execution phase
About Ruby product operator (&) and sum operator (|)
About go get and go install from Go1.16
About =
About if statement and branch processing
About object-oriented inheritance and about yield Ruby
About Java primitive types and reference types
Consideration about Rails and Clean Architecture
This and that about Base64 (Java)
About Docker, disguise server and container
About the operation of next () and nextLine ()
[About JDBC that connects Java and SQL]
About the difference between irb and pry
About the mechanism of the Web and HTTP
Find out about instance methods and self