最近重新安装了Eclipse,在设计一个不继承任何类的类时,不会有任何warning,但在设计一个子类时,编译器经常提示“warning”,在网上查了很多资料终于搞定了这个问题:如下
测试提示:The serializable class FormatStr does not declare a static final serialVersionUID field of type long
发现在我继承一些类时,会提示要这个,我打开所继承的类,里面是这样写的:
static final long serialVersionUID = -3387516993124229948L;
这个有什么作用呢??
如果我这个子类一定要声明这个serialVersionUID 那应该怎样构造它的值呢??自己随便写一个long值就行了吗???
网上某人解答如下:
那与jdk的版本没关系吧.
那是Eclipse提供这个提示功能给你吧.
你点它warning的icon两下Eclipse就会自动给定.
如果你不喜欢,可以把它关掉,windows -> preferences -> 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.
这个可以避开不兼容性的问题.
至于你说内存的问题,我觉得没差多少吧.
在eclipse中,当一个类继承另一个类时,总是提示一个如下问题:
“The serializable class A does not declare a static final serialVersionUID field of type long”
然后我按照eclipse的建议(add default serial Version ID),增加如下代码:
private static final long serialVersionUID = 1L;就没有错误提示了。
而且如果所定义的类没有继承其它类,也没有这个问题。
SUN官方网站解说摘要:
adcworks : Hi,
I develop with Eclipse IDE and am using the latest milestone that includes Java 5 syntax.
Since having upgraded, I get hundreds of the same warning for any class that extends another class with the following message:
Serializable class X does not declare a static final serialVersionUID field of type long.
I would like to know
a) Should I really ought to be doing something properly with this field, and if so, can you advise the best way to approach that.
b) Can I turn off these warnings. They are not in the Eclipse filter to exclude.
c) Is it safe to ignore them?
Thanks!
> a) Should I really ought to be doing something
> properly with this field, and if so, can you advise
> the best way to approach that.
Yes, if you actually serialize those objects. It can make version maintenance easier.
> b) Can I turn off these warnings. They are not in the Eclipse filter to exclude.
You turn them off on the Preferences | Compiler | Style page. It's the last item.
> c) Is it safe to ignore them?
Sure. You just won't have as much control over serialized versions.
分享到:
相关推荐
Eclipse运行TOMCAT 出现在a java exception has occurred的解决办法。
Eclipse没反应或反应慢的解决办法 在eclipse中导入了一个很大的项目,然后就觉得eclipce变的好慢,动不动还会挂掉~ 这时候只要在eclipse的安装目录下,打开eclipce.ini文件,把默认的内存大小很改了,就应该能解决...
eclipse闪退解决办法,这个文档里涵盖了5种办法,使得大多数人解决了eclipse闪退的问题。
Add missing serial version ID (generated) Remove unnecessary casts Remove unnecessary '$NON-NLS$' tags Add unimplemented methods Sort members excluding fields, enum constants, and initializers ...
eclipse中xml文件里自动提示消失解决办法
Eclipse导入项目源码后中文乱码的解决办法
eclipse内存溢出的解决办法,让用eclipse同志们脱离痛苦。
eclipse中JS中文乱码解决的办法 txt格式的
My Eclipse 6 Serial Number
解决办法一: 1、下载eclipse-plugins.zip,解压到eclipse\plugins目录 2、修改文件eclipse\eclipse.ini,将原来的配置改为如下配置,其他的配置不动,只改第二行,第四行。 -startup plugins/org.eclipse...
在本篇文章里小编给大家分享的是关于在eclipse中中文汉字乱码的解决方案,有需要的朋友们可以学习下。
对 eclipse 开发时 遇到的 maven 配置的问题 做出了处理
eclipse ALT+/ 失效的解决办法
Eclipse4.2 无法创建 Android 2.3解决办法
升级到3.7Eclipse最直观的反映就是,中文怎么那么小啊………… 相当不方便。 其实这是Eclipse的默认字体换了,以前的一直是Courier New,现在修改字体也找不到了,算了不找了。 这次eclipse用的字体是Consolas,这...
eclipse新增插件后发现不了的解决办法eclipse新增插件后发现不了的解决办法eclipse新增插件后发现不了的解决办法eclipse新增插件后发现不了的解决办法
仅为一般问题解决办法,不一定能完全解决
[Eclipse_Version4.6.1_Build-20161007-1200]绿色版 (分卷压缩,6个rar包大小共486M) 包括: Eclipse_Version4.6.1软件 Eclipse_JeeNeon-首选项导入.epf配置 以集成jadClipse反编译插件.txt插件 以集成svn插件
Eclipse和MyEclipse中properties文件支持中文的解决办法
# lombok.jar拷到eclipse目录,.ini文件中添加下面的配置 -javaagent:lombok.jar -Xbootclasspath/a:lombok.jar