Topic: 在eclipse开发环境中继承类时的一个问题 |
Print this page |
1.在eclipse开发环境中继承类时的一个问题 | Copy to clipboard |
Posted by: snowbird2005 Posted on: 2005-06-10 20:32 在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; 就没有错误提示了。 如果所定义的类没有继承其它类,也没有这个问题。 这个问题好象不影响使用,但每回都加这个东西,觉得很不自在。 谁知道怎么回事? |
2.Re:在eclipse开发环境中继承类时的一个问题 [Re: snowbird2005] | Copy to clipboard |
Posted by: why Posted on: 2005-06-10 20:45 It's not 1.5 specific but no compiler warning is generated in the past. You can tune this in Project Properties --> Enable project specific settings --> Potential programming problems http://java.sun.com/j2se/1.5.0/compatibility.html Incompatibilities in the Java 2 Platform Standard Edition 5.0 (since 1.4.2) 7. Serialization - Changes in compiler-generated synthetics affect the default serial version UID, and therefore can cause serialization incompatibility when that UID is not explicitly overridden. http://java.sun.com/j2se/1.4/compatibility.html Incompatibilities Between Java 2 Platform, Standard Edition, v1.4.0 and v1.3 2. If a serializable nested class contains explicit references to a class object (for example, "Foo.class"), then the computed value of the default serial version UID for both the nested class and its enclosing class will be different in J2SE 1.3 and J2SE 1.4. The difference is due to the fact that the computation of the serial version UID is sensitive to modifications made in the javac compiler between J2SE 1.3 and J2SE 1.4. To avoid this problem affecting your applications, we recommend that you add an explicit serial version UID to your serializable classes. You can use the serialver tool to obtain the serial version UID of classes compiled with the J2SE 1.3 javac compiler. |
3.Re:在eclipse开发环境中继承类时的一个问题 [Re: snowbird2005] | Copy to clipboard |
Posted by: snowbird2005 Posted on: 2005-06-10 23:12 我照你的方法改过来了。现在是没有警告了。 但我对这个问题的实质还不是很清楚。 这里的serializable是指可串行化吗? 串行化是实现对运行期的对象的存取。 不同版本的编译器(如1.3,1.4,1.5)产生的serial version UID可能不同? 请问是不是每个版本对应一个固定的serial version UID? serial version UID 到底有什么用? 为什么只有在我使用extends继承其他类时才会出现这个提示? |
Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1 客服电话 18559299278 客服信箱 714923@qq.com 客服QQ 714923 |