• Post Reply Bookmark Topic Watch Topic
  • New Topic

Serialization of Static Field

 
Andrew Prinoli
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have a simple class with 2 constructors.(It's very long so I won't paste it..).
I assign the value of a boolean static field according to the used constructor.
I also have implemented serialize/deser methods.

My problem is the following :
I have to perform different serialization/deserialization actions according to the constructor..so to the static field...but the static field doesn't preserve its value..
How should I do that??
How should I discrimine between them?
 
Rob Spoor
Sheriff
Posts: 20822
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could serialize the boolean value as well:
 
Peter Lawrey
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Perhaps your field should be a member field.
Its generally a bad idea to set a static field in a constructor.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!