Serialization and non public constructors
1 posts in topic
Flat View  Flat View

Posted By:   Adrian_Sosialuk
Posted On:   Monday, February 27, 2006 05:43 PM

Could anybody please tell me why you need to have a public
constructor (not a package access for instance) when you use Externalizable interface ?
I understand that when jvm needs to deserialize an object using Externalizable interface, it needs to call object's
constructor. But why if it's not public it can't be called
even when all classes exist in the same package ?
I would go for an answer that it's probably because it is
deserialized by a class which is in another package (I'm talking about the real mechanizm of serialization/deserialization which is in some class in some package which actually does all this work). Am I right ?

Re: Serialization and non public constructors

Posted By:   Vitali_Chkliar  
Posted On:   Wednesday, April 19, 2006 02:13 PM

java.io.ObjectStreamClass.newInstance() method has the following line: return cons.newInstance(new Object[0]); where cons is java.lang.reflect.Constructor

I think it will fail if no args constructor is not public.
About | Sitemap | Contact