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
|
|
0
|
|
|
|
Reply
|
ZalekBloom (137)
|
6/28/2008 4:23:07 PM |
|
zalek <zalekbloom@hotmail.com> writes:
> 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:
>
> public class A extends Object implements Serializable{
> int a;
> }
>
> 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
--
Lasse Reichstein Nielsen
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
|
|
0
|
|
|
|
Reply
|
lrn (235)
|
6/28/2008 4:32:58 PM
|
|
On Jun 28, 12:32 pm, Lasse Reichstein Nielsen <l...@hotpop.com> wrote:
> zalek <zalekbl...@hotmail.com> writes:
> > 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:
>
> > public class A extends Object implements Serializable{
> > int a;
> > }
>
> > 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
> --
> Lasse Reichstein Nielsen
> DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
> 'Faith without judgement merely degrades the spirit divine.'
Thanks!!!
Zalek
|
|
0
|
|
|
|
Reply
|
ZalekBloom (137)
|
6/28/2008 4:43:26 PM
|
|
Lasse Reichstein Nielsen wrote:
> zalek <zalekbloom@hotmail.com> writes:
>
>> 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.
Actually, It has uses as a Type, but unfortunately the original
*ObjectStream API developers saw fit to accept "Object" instead of
Serializable.
>
>> 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:
>>
>> public class A extends Object implements Serializable{
>> int a;
>> }
>>
>> 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
--
Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>
|
|
0
|
|
|
|
Reply
|
newsgroup.spamfilter (920)
|
6/28/2008 5:20:47 PM
|
|
Daniel Pitts <newsgroup.spamfilter@virtualinfinity.net> writes:
[Serializable]
> Actually, It has uses as a Type, but unfortunately the original
> *ObjectStream API developers saw fit to accept "Object" instead of
> Serializable.
True, I have used Serializable for parameters to serialization helper
methods.
I would prefer it as an annotation, but I also want to add annotation
restrictions to parameters, e.g., something like:
void <T extends MyType & @MySerializable> doSomething(T param)
/L
--
Lasse Reichstein Nielsen
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
|
|
0
|
|
|
|
Reply
|
lrn (235)
|
6/28/2008 5:52:00 PM
|
|
zalek wrote:
> 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/>
|
|
0
|
|
|
|
Reply
|
markspace (954)
|
6/28/2008 6:01:55 PM
|
|
Lasse Reichstein Nielsen wrote:
> Daniel Pitts <newsgroup.spamfilter@virtualinfinity.net> writes:
>> Actually, It has uses as a Type, but unfortunately the original
>> *ObjectStream API developers saw fit to accept "Object" instead of
>> Serializable.
>
> True, I have used Serializable for parameters to serialization helper
> methods.
>
> I would prefer it as an annotation, but I also want to add annotation
> restrictions to parameters, e.g., something like:
> void <T extends MyType & @MySerializable> doSomething(T param)
Annotations did not exist when Serializable was invented, so that
was not an option. And probably never will be an option either due
to compatibility.
..NET has it as an annotation (called attribute in .NET terminology).
BTW, if you want to restrict in template then I really think that
interface would fit best. To me restrictions are "is a".
Arne
|
|
0
|
|
|
|
Reply
|
arne6 (9485)
|
6/28/2008 7:27:24 PM
|
|
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.
--
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com
|
|
0
|
|
|
|
Reply
|
see_website (4858)
|
6/29/2008 1:29:12 AM
|
|
Mark Space wrote:
> zalek wrote:
>> 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/>
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
|
|
0
|
|
|
|
Reply
|
mscottschilling (1976)
|
6/29/2008 3:16:04 AM
|
|
Mike Schilling wrote:
> Mark Space wrote:
>> zalek wrote:
>>> 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/>
>
> 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
|
|
0
|
|
|
|
Reply
|
arne6 (9485)
|
6/29/2008 3:38:01 AM
|
|
Lasse Reichstein Nielsen wrote:
> Daniel Pitts <newsgroup.spamfilter@virtualinfinity.net> writes:
>
> [Serializable]
>> Actually, It has uses as a Type, but unfortunately the original
>> *ObjectStream API developers saw fit to accept "Object" instead of
>> Serializable.
>
> True, I have used Serializable for parameters to serialization helper
> methods.
>
> I would prefer it as an annotation, but I also want to add annotation
> restrictions to parameters, e.g., something like:
> void <T extends MyType & @MySerializable> doSomething(T param)
>
> /L
I think I would prefer a (more verbose but) more explicit syntax:
void <T extends @TypeAnnotatedWith(@MySerializable) MyType>
doSomething(T param)
but that's another story.
--
Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>
|
|
0
|
|
|
|
Reply
|
newsgroup.spamfilter (920)
|
6/30/2008 3:02:01 PM
|
|
|
10 Replies
22 Views
(page loaded in 0.128 seconds)
Similiar Articles: Unix Systems Programming Newbie - exec format error - comp.unix ...I'm writting a C/sockets client interface on Solaris. ... errno 8: Exec format > error". > [snip] I don't understand ... Also, I don't want to mess with it changing the ... Are newbie questions OK in here? - comp.lang.asm.x86... aux stuff that could set up an effective interface for ... cl > } > } It's just this kind of code I don't understand. ... Are newbie questions OK in here? - comp.lang.asm.x86 ... Newbie's first FPGA board ! - comp.arch.fpgaThis MAC chip has a nice interface and is supposed to be ... I hate it when the pins don't fit in the holes. And ... Newbie's first FPGA board ! - comp.arch.fpga vhdl code ... input & output in assembly - comp.lang.asm.x86I'm a complete newbie so plz excuse Theoretical bit: There isn't anything like "cin ... thereof). > > > Sorry, but I don't understand how a easy to use OS interface ... Misuses of RTTI - comp.lang.c++.moderated... 2B%2B_Programming/RTTI I don't understand the ... such as virtual functions, interfaces ... for different languages and I don't have to synchronize all the serialization ... General X10 question - comp.home.automationX10 PC Interface upgrade - comp.home.automation General ... protocols.time.ntp... topic, but I don t know other ... sorts of combinations of the -f flag which I understand ... Transparency of BMP image pixels - comp.graphics.api.opengl ...I understand that the problem is that I can't set the alpha values of the BMP's ... able to edit the alpha layer) I don't even ... for the price, with JOGL for OpenGL interface ... T1000/T2000 + ZFS + SAS performance - comp.unix.solaris... we don't ... FC-newbie question, but I'm not following your math. 12 * 1 I get (1 FC cable from each of the 12 arrays to the one SAN switch), but don't understand ... interface ... How can I add an extra character or symbol to an existing ttf file ...... next day or so. > <g> > Cerulean - What I don't understand ... Now had I mapped incorrectly, since I'm a newbie ... Developers wishing to add a new type of JTAG interface ... gnuplot's tiny problems - comp.graphics.apps.gnuplotFor the interface I need only a tiny subset of gnuplot. ... in simple terms then with very little ... you don't understand ... Are newbie questions OK in here? - comp.lang.asm.x86 ... Understand when to serialize v. externalize objects in Java ...... if it implements the Serializable interface. He also describes how you can control t ... Understand when to serialize v ... after object length, so don't ... Java RMI: Chapter 10: Serialization - O'Reilly Media - Technology ...If the superclass implements the Serializable interface, then you don't ... algorithm and protocol, so you can understand how the various hooks for customizing serialization ... 7/22/2012 12:23:22 PM
|