java – What does it mean: The serializable class does not declare a static final serialVersionUID field?
java – What does it mean: The serializable class does not declare a static final serialVersionUID field?
From the javadoc:
The serialization runtime associates with each serializable class a version number, called a
serialVersionUID
, which is used during deserialization to verify that the sender and receiver of a serialized object have loaded classes for that object that are compatible with respect to serialization. If the receiver has loaded a class for the object that has a differentserialVersionUID
than that of the corresponding senders class, then deserialization will result in anInvalidClassException
. A serializable class can declare its ownserialVersionUID
explicitly by declaring a field namedserialVersionUID
that must be static, final, and of type long:
You can configure your IDE to:
- ignore this, instead of giving a warning.
- autogenerate an id
As per your additional question Can it be that the discussed warning message is a reason why my GUI application freeze?:
No, it cant be. It can cause a problem only if you are serializing objects and deserializing them in a different place (or time) where (when) the class has changed, and it will not result in freezing, but in InvalidClassException
.
The other answers so far have a lot of technical information. I will try to answer, as requested, in simple terms.
Serialization is what you do to an instance of an object if you want to dump it to a raw buffer, save it to disk, transport it in a binary stream (e.g., sending an object over a network socket), or otherwise create a serialized binary representation of an object. (For more info on serialization see Java Serialization on Wikipedia).
If you have no intention of serializing your class, you can add the annotation just above your class @SuppressWarnings(serial)
.
If you are going to serialize, then you have a host of things to worry about all centered around the proper use of UUID. Basically, the UUID is a way to version an object you would serialize so that whatever process is de-serializing knows that its de-serializing properly. I would look at Ensure proper version control for serialized objects for more information.
java – What does it mean: The serializable class does not declare a static final serialVersionUID field?
The reasons for warning are documented here, and the simple fixes are to turn off the warning or put the following declaration in your code to supply the version UID. The actual value is not relevant, start with 999 if you like, but changing it when you make incompatible changes to the class is.
public class HelloWorldSwing extends JFrame {
JTextArea m_resultArea = new JTextArea(6, 30);
private static final long serialVersionUID = 1L;
Related posts on java :
- javascript – React Native fixed footer
- javascript – How to run html file on localhost?
- javascript – React store.getState is not a function
- javascript – How to fix TypeError: Failed to fetch?
- javascript – How does group by works in sequelize?
- javascript – GraphQL optional Query Arguments
- java – Exception: Unexpected end of ZLIB input stream
- javascript – How to use preload.js properly in Electron
- javascript – How to reload/refresh jQuery dataTable?