Results 1 to 6 of 6
- 05-04-2008, 04:43 PM #1
When compiling the code below the following warning is displayed:
The serializable class SimpleFrame does not declare a static final serialVersionUID field of type long
Having declared it the warning re-appears. Any idea what Eclipse 3.1.1 is expecting?
* @version 1.32 2007-06-12
* @author Cay Horstmann
public class SimpleFrameTest
static final long serialVersionUID = 0; //what format is commonly used here?
public static void main(String args)
SimpleFrame frame = new SimpleFrame();
class SimpleFrame extends JFrame
public static final int DEFAULT_WIDTH = 300;
public static final int DEFAULT_HEIGHT = 200;
- 05-04-2008, 05:10 PM #2
If you don't know what it is don't worry about it.My IP address is 127.0.0.1
- 05-04-2008, 05:49 PM #3static final long serialVersionUID = 0;
eg. static final long serialVersionUID = 0L;
The compiler asks about the constant.
Is it an int, float, byte, short or long datatype?freedom exists in the world of ideas
- 05-04-2008, 06:39 PM #4
It's a long value. Still the warning will remain a nuisance :-)
My understanding is that this is a version control mechanism used in serialization/deserialization of objects to/from external sources (e.g. xml files, databases) to classes. Presumably this concerns mostly J2EE (server) programming.
"In anticipating the need to evolve a serializable class, Java serialization provides a serialVersionUID, also called suid,
in the ObjectStreamClass for version control. suid is used to inform the Java serialization mechanism which version of
the class is compatible with this serialized object. However, the importance of this field is often overlooked,
resulting in release incompatibility."
Ensure proper version control for serialized objects - Java World
- 05-04-2008, 06:59 PM #5The serializable class SimpleFrame does not declare a static final serialVersionUID field of type long
You've initialized it at SimpleFrameTest.
Try to cut it and paste in inside the SimpleFrame class.freedom exists in the world of ideas
- 05-04-2008, 09:16 PM #6
Every class implementing Serializable or extending a class that implements Serializable has a class version number generated by the compiler unless you specify the version number using serialVersionUID. This is useful when you serialize objects on the disk or across the network. In the first scenario you can imagine a "disconnect" between the serialized object on the disk and the class who tries to reload it. The instance can be written on the disk by one version of the class and loaded by a new version of the class let say after an upgrade. The same is true for the network scenario, the class sending can be at a different version than the class receiving.
If your class is not involved in one of these two scenarios, then just declaring the serialVersionUID = 1L is enough. If you actually use the serialization mechanism then you have to do more work in order to ensure your code doesn't break when you change the Serializable classes. This will involve implementing your own version of readObject and writeObject methods:
private void readObject(ObjectInputStream in) throws ClassNotFoundException, IOException private void writeObject(ObjectOutputStream out) throws IOException
Last edited by danielstoner; 05-04-2008 at 09:18 PM.Daniel @ [www.littletutorials.com]
Language is froth on the surface of thought