2

whenever I see this line of code

private static final long serialVersionUID =

it's always followed by some long serial number.. how is this number generated? If I wanted to randomly generate this value, how would I go about that? thanks for any help.

Elaina Heraty
  • 51
  • 1
  • 3
  • Most IDEs offer a way to generate the serialVersionUID. However you should ask yourself if you actually need one. If you don't add a serialVersionUID it will be generated based on properties of you're class. This will work just fine as long as you don't write the Object with an ObjectOutputStream, change the code of the class and then want to read it with an ObjectInputStream. – magicmn Jul 14 '20 at 22:36

1 Answers1

3

JDK

The JDK ships a tool called serialver. You give it a classname and it will generate a serialVersionUID for you. For example:

$serialver  java.lang.String
java.lang.String:    private static final long serialVersionUID = -6849794470754667710L;

IntelliJ

For the IntelliJ IDE, try: IntelliJ IDEA generating serialVersionUID

Basil Bourque
  • 303,325
  • 100
  • 852
  • 1,154
JCWasmx86
  • 3,473
  • 2
  • 11
  • 29