can you call .readObject from readResolve?

B

bsd_mike

I have a static integer value in a class that I am trying to serialize.


We have our own writeObject what writes the integer out each time the
object is written.
This works.

However, I would like to only write the integer out once.

I can detect when I am on the last object during a write, but can't
during a read...
except through readResolve.

Would it work to call readObject from readResolve to get that integer?

Other ideas?

-MIke
 
T

Thomas Hawtin

bsd_mike said:
I have a static integer value in a class that I am trying to serialize.


We have our own writeObject what writes the integer out each time the
object is written.
This works.

However, I would like to only write the integer out once.

I can detect when I am on the last object during a write, but can't
during a read...
except through readResolve.

Would it work to call readObject from readResolve to get that integer?

I'm not exactly sure what you are after.

If you are trying to serialise a static field, I think the answer is to
rework your code into something sensible.

If you want a serialised object to stand in for a reference to a
particular static field value, then readResolve seems sensible (I'm not
exactly sure on the rules for static typing on that). I don't know why
you would want to manipulate the stream from readResolve.

Tom Hawtin
 
R

Robert Klemme

bsd_mike said:
I have a static integer value in a class that I am trying to serialize.

There is no point in serializing static data as it will always be there
(always meaning as long as the class is loaded).
Other ideas?

Change your code to remove the necessity to serialize static content.

Kind regards

robert
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top