can you call .readObject from readResolve?

Discussion in 'Java' started by bsd_mike, Oct 5, 2006.

  1. bsd_mike

    bsd_mike Guest

    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
     
    bsd_mike, Oct 5, 2006
    #1
    1. Advertising

  2. bsd_mike wrote:
    > 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
     
    Thomas Hawtin, Oct 5, 2006
    #2
    1. Advertising

  3. bsd_mike wrote:
    > 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
     
    Robert Klemme, Oct 5, 2006
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Serial # 19781010
    Replies:
    1
    Views:
    738
    Roedy Green
    Jul 15, 2003
  2. mitch gart
    Replies:
    1
    Views:
    380
    David Zimmerman
    Oct 18, 2003
  3. Jim Garrison
    Replies:
    0
    Views:
    424
    Jim Garrison
    Oct 21, 2003
  4. juicy
    Replies:
    28
    Views:
    2,425
    Andrew Thompson
    Sep 25, 2004
  5. Replies:
    1
    Views:
    4,452
    Harish
    Jan 7, 2005
Loading...

Share This Page