The interface Serializable does not have any methods or variables.
If I create a subclass of an Object class - is this class
Serializable?
For example, let say I define:
public class A extends Object{
int a;
}
Now make the following definition:
public class A extends Object implements Serializable{
int a;
}
What makes the 2nd definition Serializable?
Thanks,
Zalek
Lasse Reichstein Nielsen - 28 Jun 2008 17:32 GMT
> The interface Serializable does not have any methods or variables.
Correct. It's a "marker interface" which merely marks the class as being
intended for serialization. The serialization code checks for the marker,
and refuses to serialize something without it - not because it couldn't,
but just because it won't - serializing and derserializing something not
build for it could cause unexpected trouble.
Today it would probably have been implemented as an inherited
annotation.
> If I create a subclass of an Object class - is this class
> Serializable?
If it implements the Serializable interface.
> For example, let say I define:
>
> public class A extends Object{
> int a;
> }
Yes, that class isn't serializable. No need to write the "extends Object".
The class will automatically extend Object if no other superclass is
given.
> Now make the following definition:
>
[quoted text clipped - 3 lines]
>
> What makes the 2nd definition Serializable?
That it implements the interface! That means that the default
serialization code will accept to serialize and deserialize objects
of that class.
/L

Signature
Lasse Reichstein Nielsen
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Mark Space - 28 Jun 2008 19:01 GMT
> The interface Serializable does not have any methods or variables.
> If I create a subclass of an Object class - is this class
> Serializable?
Lasse gave you some really good answers to your questions. Here's a
decent how-to on serialization from Sun. It explains further how
serialization actually works and gives some guidelines how to use it.
<http://java.sun.com/developer/technicalArticles/Programming/serialization/>
Mike Schilling - 29 Jun 2008 04:16 GMT
>> The interface Serializable does not have any methods or variables.
>> If I create a subclass of an Object class - is this class
[quoted text clipped - 6 lines]
>
> <http://java.sun.com/developer/technicalArticles/Programming/serialization/>
And her is everything you'd ever want to know about serialization:
http://java.sun.com/j2se/1.3/docs/guide/serialization/spec/serialTOC.doc.html
Arne Vajhøj - 29 Jun 2008 04:38 GMT
>>> The interface Serializable does not have any methods or variables.
>>> If I create a subclass of an Object class - is this class
[quoted text clipped - 9 lines]
> And her is everything you'd ever want to know about serialization:
> http://java.sun.com/j2se/1.3/docs/guide/serialization/spec/serialTOC.doc.html
I don't think it has changed, but:
http://java.sun.com/javase/6/docs/platform/serialization/spec/serialTOC.html
Arne
Roedy Green - 29 Jun 2008 02:29 GMT
On Sat, 28 Jun 2008 09:23:07 -0700 (PDT), zalek
<zalekbloom@hotmail.com> wrote, quoted or indirectly quoted someone
who said :
>The interface Serializable does not have any methods or variables.
>If I create a subclass of an Object class - is this class
>Serializable?
>For example, let say I define:
it is just marker to indicate you have thought through the class to do
the transients etc. needed to make it serialisable.

Signature
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com