serialVersionUID of Java enum class

origin

  When I was typing code in the company recently, I accidentally found that the enumeration class left before implements the Serializable interface, and then wrote a serialVersionUID... I have never used it in an enumeration class before. It feels a bit magical... .So Baidu searched and tested it by myself.. Recorded this article

 

Specific content

The enumeration implements the Serializable interface by default

After Baidu, it was found that the enumeration class implements this serialization interface by default, so there is no need to additionally impl Serializable when declaring the enumeration type.

 

Enumeration classes do not need to write serialVersionUID themselves

The enumeration class does not need to define serialVersionUID, nor is it necessary, the default is 0, even if you write serialVersionUID yourself, it is also 0.

This is the conclusion drawn from the test, and the specific test process will be seen later.

 

Test serialVersionUID of enum class

SerialVersionUID is calculated using serialver 

serialver -show

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325767921&siteId=291194637