What is the serialVersionUID?

23 views
Skip to first unread message

Same Diffr

unread,
Nov 29, 2013, 7:09:59 AM11/29/13
to peerfac...@googlegroups.com
In Java files like "JoinMsg.java" (package: org.peerfact.impl.overlay.dht.pastry.base.messages) I find a variable:
private static final long serialVersionUID = -7372693081066186219L;

What is the meaning / use of this variable?

Reason of this question:
I want to add some new message types to the message package of Pastry.

Does every new message type I create need such a serialVersionUID?
If yes, how should I choose / determine it's value?

Best regards

Philipp Giesen

unread,
Nov 29, 2013, 7:21:50 AM11/29/13
to peerfac...@googlegroups.com
It's used for serialization of a class object. StackOverflow offers a
good explanation: http://stackoverflow.com/a/285809/2674385

You can also look into the docs of java.io.Serializable to get a grasp
on the basics of Serialization in Java.
http://docs.oracle.com/javase/7/docs/api/java/io/Serializable.html

Short answers: It is highly recommended you do implement it.

Regards,
Philipp
> --
> You received this message because you are subscribed to the Google Groups
> "PeerfactSim.KOM" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to peerfactsim-k...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.

Same Diffr

unread,
Nov 29, 2013, 8:44:04 AM11/29/13
to peerfac...@googlegroups.com
Thank you for your answer, Philipp.

As I understood, I definitely need to assign a serialVersionUID for every message type I am adding to the source code. My question is now: How?

What do I have to keep in mind when assigning it? Do I have to avoid declaring one that is already existing in some code of the simulator? How did the developers of the simulator come up with such huge long (datatype) numbers? Can I just use a random long number with the same length as one existing serialVersionUID?

Best regards 
Reply all
Reply to author
Forward
0 new messages