This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Java in General and the fly likes  serialVersionUID Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark " serialVersionUID" Watch " serialVersionUID" New topic


Isaac Ferguson
Ranch Hand

Joined: Jun 22, 2012
Posts: 331
Why some classes ask me for

Henry Wong

Joined: Sep 28, 2004
Posts: 18508

Angus Ferguson wrote:Why some classes ask me for


Well, no classes "ask" for the variable.

However, some IDE warns you that you have a serializable class without it. The theory behind it is .. if you don't provide it, the Java compiler will generate one based on a formula. And chances are, it will be too volatile, meaning it will change the value even though you don't care about the part that changes.

So... the theory is, if the programmer controls it, then the programmer can change it only when actually needed. This way, if the programmer changes an interim variable, the programmer can choose to not change the ID, and hence, the program will still be compatible with all the previously serialized files.... and of course, this is based on the assumption that the programmer knows what he/she is doing.


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
I agree. Here's the link:
subject: serialVersionUID
Similar Threads
About serialVersionUID
private static final long serialVersionUID = 1L; - Don't exist unique at a class that extends...
class versioning
object byte array to object instance
sending org.jdom.Document object over JMS