码迷,mamicode.com
首页 > 其他好文 > 详细

serialVersionUID的作用

时间:2019-11-04 19:50:54      阅读:100      评论:0      收藏:0      [点我收藏+]

标签:oracl   ase   javase   nbsp   val   verify   oci   数据   declare   

Java中serialVersionUID的作用

The serialization runtime associates with each serializable class a version number, called a serialVersionUID, 
which is used during deserialization to verify that the sender and receiver of a serialized object have loaded classes
for that object that are compatible with respect to serialization.
If the receiver has loaded a class for the object that has a different serialVersionUID than that of the corresponding sender‘s class,
then deserialization will result in an InvalidClassException.
A serializable class can declare its own serialVersionUID explicitly by declaring a field named serialVersionUID that must be static, final, and of type long

一言以蔽之,就是为了在反序列化时验证数据发送者,防止中间有人篡改

 

参考:

https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/io/Serializable.html

https://stackoverflow.com/questions/285793/what-is-a-serialversionuid-and-why-should-i-use-it

serialVersionUID的作用

标签:oracl   ase   javase   nbsp   val   verify   oci   数据   declare   

原文地址:https://www.cnblogs.com/roostinghawk/p/11790970.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!