关于The serializable class XXX does not declare a static final serialVersionUID field of type long的警告
编写实体类并且继承序列化接口时候,实体类会有警告,要生成一个静态的serialVersionUID。
上网搜了一下资料,现通俗解释一下:
点击前2个选项,会生成:
private static final long serialVersionUID = 474750103221294654L;
serialVersionUID用来作为Java对象序列化中的版本标示之用;
如果一个序列化类没有声明这样一个static final的产量,JVM会根据各种参数为这个类计算一个;
对于同样一个类,不同版本的JDK可能会得出不同的serivalVersionUID;
The serializable class XXX does not declare a static final serialVersionUID field of type long
serialVersionUID作用:
序列化时为了保持版本的兼容性,即在版本升级时反序列化仍保持对象的唯一性。
你可以随便写一个,在Eclipse中它替你生成一个,有两种生成方式:
一个是默认的1L,比如:private static final long serialVersionUID = 1L;
一个是根据类名、接口名、成员方法及属性等来生成一个64位的哈希字段,比如:private static final long serialVersionUID = -8940196742313994740L;之类的。
当你一个类实现了Serializable接口,如果没有定义serialVersionUID,Eclipse会提供这个提示功能告诉你去定义之。
在Eclipse中点击类中warning的图标一下,Eclipse就会自动给定两种生成的方式,如上面所述。如果不想定义它,在Eclipse的设置中也可以把它关掉的,设置如下:
Window ==> Preferences ==> Java ==> Compiler ==> Error/Warnings ==> Potential programming problems
将Serializable class without serialVersionUID的warning改成ignore即可。
如果你没有考虑到兼容性问题时,就把它关掉,不过有这个功能是好的,只要任何类别实现了Serializable这个接口的话,如果没有加入
serialVersionUID,Eclipse都会给你warning提示,这个serialVersionUID为了让该类别
Serializable向后兼容。
如果你的类Serialized存到硬盘上面后,可是后来你却更改了类别的field(增加或减少或改名),当你Deserialize时,就会出现Exception的,这样就会造成不兼容性的问题。
但当serialVersionUID相同时,它就会将不一样的field以type的预设值Deserialize,这个可以避开不兼容性的问题。
关于The serializable class XXX does not declare a static final serialVersionUID field of type long的警告的更多相关文章
- The serializable class XXX does not declare a static final serialVersionUID field of type long的警告
原文: http://blog.csdn.net/ultrakang/article/details/41820543
- The serializable class XXX does not declare a static final serialVersionUID field of type long
问题: 在Eclipse中,继承类时,总是提示下面的警告(Warning),按理说警告是没有关系的,但是程序看起来老不爽了,这是强迫症的关系(呵呵) The serializable class XX ...
- Eclipse警告:The serializable class XXX does not declare a static final serialVersionUID field of type long
serialVersionUID作用: 序列化时为了保持版本的兼容性,即在版本升级时反序列化仍保持对象的唯一性. 在Eclipse中可以自动生成,有两种生成方式: 一个是默认的1L,比如:privat ...
- Eclipse下关于The serializable class UsersServlet does not declare a static final serialVersionUID field of type的警告
The serializable class XXX does not declare a static final serialVersionUID field of type long seria ...
- The serializable class does not declare a static final serialVersionUID field of type long
在编译以下Java程序时,出现The serializable class does not declare a static final serialVersionUID field of typ ...
- the serializable class XXX does not declare a static final seriaVersionUID...的问题
关于myeclips提示The serializable class XXX does not declare a static final serialVersionUID field of typ ...
- java 输入输出 对象序列化implements Serializable与反序列化:ObjectOutputStream.writeObject() ;objectInputStream.readObject() ;serialVersionUID字段注意
对象序列化 对象序列化的目标是将对象保存到磁盘中,或允许在网络中直接传输对象.对象序列化机制允许把内存中的 Java 对象转换成平台无关的二进制流,从而允许把这种二进制流持久地保存在磁盘上,通过网络将 ...
- 【转载】Understand the serialVersionUID
If you have ever implemented Serializable interface, you must encounter this warning message The ser ...
- private static final long serialVersionUID = 1L;详解
public class User implements Serializable { /** * serialVersionUID */ private static final long seri ...
随机推荐
- CUDA2.3-原理之任意长度的矢量求和与用事件来测量性能
__global__ void add( int *a, int *b, int *c) { <span style="white-space:pre"> </s ...
- 浅谈WCF的三种通信模式:请求响应模式、数据报模式和双工通讯模式
一: WCF的服务端与客户端在通信时有三种模式:请求响应模式.数据报模式和双工通讯模式. 说一下基本知识, 1.如果想要将当前接口作为wcf服务器,则一定要加上[ServiceContract] 契 ...
- asp.net、 mvc session影响并发
现象:在一个网站中,当访问一个处理比较耗时的页面(A页面),页面请求还没有返回时,此时再点击访问该网站的其他页面(B页面)会出现B页面很久都没有响应和返回,直到A页面输出返回数据时才开始处理B页面的请 ...
- [BZOJ1263][SCOI2006]整数划分(数学+高精度)
题目:http://www.lydsy.com:808/JudgeOnline/problem.php?id=1263 分析:数学老师上课讲过啦= =,就是尽可能3越多越好.然后就写个高精度就行了.
- Spearman Rank(斯皮尔曼等级)相关系数及MATLAB实现
转自:http://blog.csdn.net/wsywl/article/details/5859751 Spearman Rank(斯皮尔曼等级)相关系数 1.简介 在统计学中,斯皮尔曼等级相关系 ...
- js中各种宽度高度总结
offsetWidth 是对象的可见宽度,包滚动条等边线,会随窗口的显示大小改变 IE6.0.FF1.06+:offsetWidth = width + padding + borderoffsetH ...
- 【JavaEE企业应用实战学习记录】requestListener
package sanglp.servlet; import javax.servlet.*; import javax.servlet.annotation.WebListener; import ...
- CentOS6.6搭建LNMP环境
CentOS6.6搭建LNMP环境 1.设置yum源,本地安装依赖包 1 yum -y install gcc gcc-c++ automake autoconf libtool make 2.下载依 ...
- auto refresh iframe
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <t ...
- android 获取时间
首先,先说下java下可以正常使用的方法: import java.text.DateFormat; import java.text.SimpleDateFormat; import java.ut ...