Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Serialization

807603Feb 16 2008 — edited Feb 17 2008
Hi guys, just thought of something interesting. If I had these two classes:
class A implements Serializable{
    int a1;
    int a2;
    public void method(){
    }
}

class B implements Serializable{
    int a1;
    int a2;
}
and serialized an instance of A, and then tried to deserialize it as an instance of B, would it work?

According to what I read, when serializing, java only stores the fields(the state of the instance) but no methods. so method() in class A wouldn't matter at all in serialization?

When deserializing, would java look at the field names to match them or how?

just thought this might be interesting.

Cheers,

Jing

Edited by: J.T on Feb 16, 2008 5:31 AM

Edited by: J.T on Feb 16, 2008 5:32 AM

Edited by: J.T on Feb 16, 2008 5:34 AM
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 16 2008
Added on Feb 16 2008
5 comments
396 views