可是,我想弄清楚第二个警告是什么意思? testCalculator.java:17: warning: [serial] serializable class fpack.CalculatorFrame has no definition of serialVersionUID class CalculatorFrame extends JFrame难道说JFrame类也不被推荐了?顺便说一下,我是用的java 1.5
serialVersionUID is used to determine whether the version of a class being read from a serialization source is the same as that written. You can define your own but if you don't the compiler creates one for you. Java 1.5 emphasizes the dangers of the latter option http://java.sun.com/j2se/1.5.0/docs/guide/serialization/relnotes15.html http://java.sun.com/j2se/1.5.0/docs/api/java/io/Serializable.html http://java.sun.com/j2se/1.5.0/docs/guide/serialization/spec/serialTOC.html simply you can add public static final long serialVersionUID = 123456789L;// just a long to your class.
serialVersionUID is used to determine whether the version of a class being read from a serialization source is the same as that written. You can define your own but if you don't the compiler creates one for you. Java 1.5 emphasizes the dangers of the latter option http://java.sun.com/j2se/1.5.0/docs/guide/serialization/relnotes15.html http://java.sun.com/j2se/1.5.0/docs/api/java/io/Serializable.html http://java.sun.com/j2se/1.5.0/docs/guide/serialization/spec/serialTOC.html simply you can add public static final long serialVersionUID = 123456789L;// just a long to your class.
将方法CalculatorFrame 改成 TT_CalculatorFrame然后用javac -d . -Xlint testCalculator.java
警告没变。
看来不是package的问题,是我说错了。
而frame.show()确实是不被推荐使用的。
有谁补充吗?
testCalculator.java:17: warning: [serial] serializable class fpack.CalculatorFrame has no definition of serialVersionUID
class CalculatorFrame extends JFrame难道说JFrame类也不被推荐了?顺便说一下,我是用的java 1.5
http://java.sun.com/j2se/1.5.0/docs/guide/serialization/relnotes15.html
http://java.sun.com/j2se/1.5.0/docs/api/java/io/Serializable.html
http://java.sun.com/j2se/1.5.0/docs/guide/serialization/spec/serialTOC.html
simply you can add
public static final long serialVersionUID = 123456789L;// just a long
to your class.
http://java.sun.com/j2se/1.5.0/docs/guide/serialization/relnotes15.html
http://java.sun.com/j2se/1.5.0/docs/api/java/io/Serializable.html
http://java.sun.com/j2se/1.5.0/docs/guide/serialization/spec/serialTOC.html
simply you can add
public static final long serialVersionUID = 123456789L;// just a long
to your class.
jdk1.5没用过,可能在安全性方面有很多提高。
把frame.show();换成frame.serVisible(true)
把public static final long serialVersionUID = 123456789L;(随便一个数)加到类CalculatorFrame 中。目的是兼容java 1.1.x