이클립스에서 열심히 작업을 하다 보면 보는 경고가 있다.
JDK 5.x대에서 새롭게 추가된 점인듯 하다.
The serializable class XXX does not declare a static final serialVersionUID field of type long
이 문제를 해결하기 위해 찾아보던중 다음과 같은 내용을 발견하였다.
ANY-ACCESS-MODIFIER static final long serialVersionUID = 42L;
If a serializable class does not explicitly declare a serialVersionUID, then the serialization runtime will calculate a default serialVersionUID value for that class based on various aspects of the class, as described in the Java(TM) Object Serialization Specification. However, it is strongly recommended that all serializable classes explicitly declare serialVersionUID values, since the default serialVersionUID computation is highly sensitive to class details that may vary depending on compiler implementations, and can thus result in unexpected InvalidClassExceptions during deserialization. Therefore, to guarantee a consistent serialVersionUID value across different java compiler implementations, a serializable class must declare an explicit serialVersionUID value. It is also strongly advised that explicit serialVersionUID declarations use the private modifier where possible, since such declarations apply only to the immediately declaring class–serialVersionUID fields are not useful as inherited members.
사실 무슨 말인지 정확히 모르겠지만, serializable class를 사용할 경우 serialVersionUID 를 등록하여야 한다는 말인듯 하다.
보안적인 측면에서인듯 하다.
static final long serialVersionUID = 42L;
를 클래스안에 추가해 주면 된다.