the serialVersionUID of has to be the same in all classes "Serializable"?

Asked

Viewed 43 times

0

I already have some notion about the serialVersionUID representing the class version (in bytes form) very objectively. But the version number can or should be the same in different classes ?

1 answer

0


It may be the same or it may be different as explained in the following link:

https://blog.caelum.com.br/entendendo-o-serialversionuid/

By default JDK is in charge of validating and generating the serial Windows, but in some cases you want to control your version. class so that it is compatible with previous versions, it is interesting that you have control of this version. As is the version of . class, meaning it is a version for each . class, but not necessarily can be different from others.

How then should we proceed to choose a serialVersionUID appropriate? It is very simple: if that class is being born in this moment, you can afford to use a serialVersionUID, as an example:

public class Usuario implements Serializable {   
   private static final
   long serialVersionUID = 1L;   private String login; 
}
  • 1

    Thank you Gilvan, I read this article too. I just hadn’t gotten explicit that it could be the same.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.