eclipse issues warnings when serialversionuid
missing.
the serializable class foo not declare static final serialversionuid field of type long
what serialversionuid
, why important? please show example missing serialversionuid
cause problem.
the docs java.io.serializable
explanation you'll get:
the serialization runtime associates each serializable class version number, called serialversionuid, used during deserialization verify sender , receiver of serialized object have loaded classes object compatible respect serialization. if receiver has loaded class object has different serialversionuid of corresponding sender's class, deserialization result in
invalidclassexception
. serializable class can declare own serialversionuid explicitly declaring field named "serialversionuid
" must static, final, , of typelong
:any-access-modifier static final long serialversionuid = 42l;
if serializable class not explicitly declare serialversionuid, serialization runtime calculate default serialversionuid value class based on various aspects of class, described in java(tm) object serialization specification. however, strongly recommended serializable classes explicitly declare serialversionuid values, since default serialversionuid computation highly sensitive class details may vary depending on compiler implementations, , can result in unexpected
invalidclassexceptions
during deserialization. therefore, guarantee consistent serialversionuid value across different java compiler implementations, serializable class must declare explicit serialversionuid value. advised explicit serialversionuid declarations use private modifier possible, since such declarations apply declaring class--serialversionuid fields not useful inherited members.
Comments
Post a Comment