Saturday 28 July 2018

java - what is a serial version id?




Duplicate What is a serialVersionUID and why should I use it?




Using Eclipse for some java work right now. My class name is underlined in yellow. I can either suppress the warning or just add the frickin serial id.



I dont care either way (or should i?), but what exactly IS this serial id?



thanks


Answer



It has to do with Java serialization.



When the fields of a class changes, you can no longer unserialize other versions of the class. If you try, Java will throw an exception.




However sometimes the change in fields don't matter and you want to say "unserialize anyway." To do that, you define this serial number. Now Java will use that number rather than reflection to decide whether your class definition is "different."



Finally, you can get around all this by defining your own serialization functions, and indeed many advocates insist that you should.


No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...