Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > writeObject signature

Reply
Thread Tools

writeObject signature

 
 
Roedy Green
Guest
Posts: n/a
 
      06-08-2004
I just noticed that it is writeObject ( Object o )
rather than writeObject ( Serializable o )

how come?

--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
 
Reply With Quote
 
 
 
 
Skippy
Guest
Posts: n/a
 
      06-08-2004
> I just noticed that it is writeObject ( Object o )
> rather than writeObject ( Serializable o )


I wondered the same thing, same for readObject.
Seems to me this is a design flaw.

Would have been nice to have this compile-time 'check',
before you launch the app and Exceptions are thrown..


 
Reply With Quote
 
 
 
 
Roedy Green
Guest
Posts: n/a
 
      06-08-2004
On Tue, 8 Jun 2004 15:22:14 +0200, "Skippy" <(E-Mail Removed)> wrote or
quoted :

>I wondered the same thing, same for readObject.
>Seems to me this is a design flaw.


My best explanation is that you are going to do a cast check anyway on
reconstitution, and so the cast check to Serializable it would have to
do internally would be wasted.

--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      06-08-2004
On Tue, 08 Jun 2004 14:14:14 GMT, Roedy Green
<(E-Mail Removed)> wrote or quoted :

>My best explanation is that you are going to do a cast check anyway on
>reconstitution, and so the cast check to Serializable it would have to
>do internally would be wasted.


Then why not put one on writeObject? To be parallel? To make the
name of the method logical?

--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
 
Reply With Quote
 
Liz
Guest
Posts: n/a
 
      06-08-2004

"Roedy Green" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> I just noticed that it is writeObject ( Object o )
> rather than writeObject ( Serializable o )
>
> how come?
>
> --
> Canadian Mind Products, Roedy Green.
> Coaching, problem solving, economical contract programming.
> See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.


It's obvious.


 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      06-08-2004
On Tue, 08 Jun 2004 15:21:20 GMT, "Liz" <(E-Mail Removed)> wrote or
quoted :

>news:(E-Mail Removed).. .
>> I just noticed that it is writeObject ( Object o )
>> rather than writeObject ( Serializable o )
>>
>> how come?
>>
>> --
>> Canadian Mind Products, Roedy Green.
>> Coaching, problem solving, economical contract programming.
>> See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.

>
>It's obvious.


That reminds me of a story Professor Melzak told. A math prof was
scribbling out a proof on the board. A student raised his hand, "how
did you get from step A to step B?". "It's trivial the prof replied".
"I don't see it" the student countered.


The prof stopped, and scratched his head. Eventually he left the room
to go think it over, and just before the bell, returned to the class,
and announced triumphantly "It IS trivial".


--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
 
Reply With Quote
 
lyallex
Guest
Posts: n/a
 
      06-09-2004
On Tue, 08 Jun 2004 15:21:20 GMT, "Liz" <(E-Mail Removed)> wrote:

>
>"Roedy Green" <(E-Mail Removed)> wrote in message
>news:(E-Mail Removed).. .
>> I just noticed that it is writeObject ( Object o )
>> rather than writeObject ( Serializable o )
>>
>> how come?
>>
>> --
>> Canadian Mind Products, Roedy Green.
>> Coaching, problem solving, economical contract programming.
>> See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.

>
>It's obvious.
>


Ah, great, can you tell us then.
I have just asked the most experienced java developer/architect I know
and he didn't know the answer ...

Rgds
Lyall



"Process- How will the work and the team be organized?
The team needs to fit the culture in which it will operate,
but you should write software well rather than preserve the
irrationality of an enclosing culture" - Kent Beck
 
Reply With Quote
 
Michael Rauscher
Guest
Posts: n/a
 
      06-09-2004
Roedy Green schrieb:
> I just noticed that it is writeObject ( Object o )
> rather than writeObject ( Serializable o )
>
> how come?
>


IMO: I'd say that this is because writeObject writes Objects. In it's
default implementation it writes only objects that have implemented
Serializable. But one may want to provide it's own method to write
Objects, not relying on Serializable.

Bye
Michael



 
Reply With Quote
 
lyallex
Guest
Posts: n/a
 
      06-09-2004
On Wed, 09 Jun 2004 12:44:40 +0200, Michael Rauscher
<(E-Mail Removed)> wrote:

>Roedy Green schrieb:
>> I just noticed that it is writeObject ( Object o )
>> rather than writeObject ( Serializable o )
>>
>> how come?
>>

>
>IMO: I'd say that this is because writeObject writes Objects. In it's
>default implementation it writes only objects that have implemented
>Serializable. But one may want to provide it's own method to write
>Objects, not relying on Serializable.
>
>Bye
>Michael


I thought this might be the answer until I realised that writeObject
is final and therefore can't be overridden ... there is a method
called writeObjectOverride(Object obj) that the API docs say should be
used to 'override' the default writeObject method (?) but this just
seems to reinforce the original notion that writeObject should take an
argument of type Serializable.

Do you think it could be a 'style' issue.

In fact we have just had a Development consultant here from Sun
Microsystems and even he couldn't come up with good answer.

Rgds
Lyall
>
>




"Process- How will the work and the team be organized?
The team needs to fit the culture in which it will operate,
but you should write software well rather than preserve the
irrationality of an enclosing culture" - Kent Beck
 
Reply With Quote
 
Carl Howells
Guest
Posts: n/a
 
      06-09-2004
Roedy Green wrote:
> I just noticed that it is writeObject ( Object o )
> rather than writeObject ( Serializable o )
>
> how come?
>


Because it can also write Externalizable objects. And because the
behavior of Externalizable and Serializable are different enough,
neither one is a superinterface of the other.

Of course, since the behavior of writeObject has to be significantly
different between the two interfaces, this makes one wonder why they
didn't just put two different writeObject methods in, on taking a
Serializable instance, the other taking an Externalizable instance.

I suppose the answer to that is also pretty obvious... If you have an
object that you can send through an ObjectOutputStream, and you don't
know if it's Serializable or Externalizable, someone has to do
instanceof and casts, no matter what. Might as well make them part of
the ObjectOutputStream, instead of forcing the user to write them over
and over again.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Turning a signature-changing decorator into a signature-preservingone Gustavo Narea Python 14 02-16-2009 04:58 PM
UTF-8 with signature & UTF-8 without signature JJBW ASP .Net 1 04-24-2004 10:21 AM
Socket / writeObject / NotSerializableException question JMC Java 1 04-07-2004 01:30 PM
writeObject too slow for big object, any idea? Kaidi Java 7 01-06-2004 11:32 AM
writeObject with ArrayList of ArrayList? Kaidi Java 4 01-03-2004 08:16 PM



Advertisments