1

Declaring an explicit serialVersionUID is mostly recommended for serialization but not for array classes as per the last line of javadoc for serialization

Array classes cannot declare an explicit serialVersionUID, so they always have the default computed value, but the requirement for matching serialVersionUID values is waived for array classes.

Which array classes javadoc is referring to ? I am aware of only Arrrays which is a utility class and Array which is final. So are there any more classes its concerned about ?

Why array classes can't declare an explicit serialVersionUID ?

There is another post but it doesnt explain the reason of not allowing array classes to declare serialVersionUID

Community
  • 1
  • 1
SacJn
  • 777
  • 1
  • 6
  • 16
  • Welcome to [stackoverflow] (http://stackoverflow.com/tour) please . Refer these links for asking proper questions (http://stackoverflow.com/help/how-to-ask) , (http://stackoverflow.com//help/mcve) and (http://sscce.org) – Panther Aug 11 '15 at 11:28
  • Also look this http://stackoverflow.com/questions/285793/what-is-a-serialversionuid-and-why-should-i-use-it?rq=1 – Panther Aug 11 '15 at 11:29
  • 1
    Possible duplicate of http://stackoverflow.com/questions/19233303/array-classes-with-serialversionuid – RP- Aug 13 '15 at 04:51
  • @RP- This link only repeats the statement but doesn't explain the reason ? As the link mentions **your array would have serious issues, and would be very fragile with respect to serialization** It may be very simple to understand but atleast not for me as its just doesn't hit me. – SacJn Aug 13 '15 at 05:32
  • @SACHINJAIN "Your array would have serious issues, and would be very fragile with respect to serialization " *is* the reason given. You may not understand it, but that doesn't mean it isn't present. Not that I agree with it. The real reason is that there is simply no syntax for it. Array classes are not declared at all, so they can't have members, so they can't have `serialVersionUID` members, so checking them would be a complete waste of time. – user207421 Aug 13 '15 at 05:49
  • @EJP So whats the point of making them implementing serializable ? – SacJn Aug 13 '15 at 05:53
  • Eh? So that you can serialize them, of course. – user207421 Aug 13 '15 at 06:04
  • Now it seems I am wrong at concepts. I thought **Serialization is normally done to save the state of an object and state here refers to member variables of the class** I am then probably wrong to understand the meaning of 'STATE of an object' ? Please clear me what attributes of the class contribute to state of an object ? – SacJn Aug 13 '15 at 06:22
  • In the case of an array, state refers to its elements and its length. In the case of a non-array class, serializable state refers to its non-static non-transient member variables. – user207421 Aug 13 '15 at 06:24
  • Ok. Thanks for sharing your valuable knowledge – SacJn Aug 13 '15 at 08:13
  • Well thank you, but it all seems rather trivial to me after the initial answer. – user207421 Aug 13 '15 at 08:53

0 Answers0