开发者

Class serialization in simple program, should I worry about it?

Im working on a very simple project in java that utilizes the Swing component and I have a class that when finished with all its statements, Eclipse underlines it with a yellow line and gives the warning "The serializable class HelloComponent does not declare a开发者_运维百科 static final serialVersionUID of type long"

The program works fine but whenever i create any classes other than the main one, I get this warning... Should I worry about it for now? Im a beginner in java.


If your application is not doing any object serialization, you can ignore this warning.

(Even if it does, the application will still work. It is just that serialization will be more fragile in the face of changes to the classes that are being serialized.)


You can safely ignore it if you are not going to do any serialization. However depending on what your application does... other frameworks / libraries may require serialization to work probably. (Ie object saving, remote procedure calls, database interaction.)

When in doubt just have ecilpse auto create it.


When you hover over it Eclipse should be giving you the option to create it for you. You might as well select that option and let Eclipse fill it in for you.

There are some guidelines you can read at Java Practices -> Implementing Serializable.


The warning is only applicable if your application is going to serialise the objects, and store the data persistently. It makes very little sense to serialise Swing components.


As explained by others people, if your application will not do any serialization, you can ignore the warning.

Eclipse can help you to generate a serialVersionUid attribute. Otherwise, you can annotate your class by a @SuppressWarnings("serial");

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜