• Post Reply Bookmark Topic Watch Topic
  • New Topic

readResolve() method for Singletons  RSS feed

 
Joe Harry
Ranch Hand
Posts: 10128
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Guys,

Why do I need to add such a method and return my Singleton instance when I make my Singleton class serializable?
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Otherwise if you deserialize it more than once you will have more than one instances.
 
Joe Harry
Ranch Hand
Posts: 10128
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good, I found it our by trying it. Thanks!
 
Joe Harry
Ranch Hand
Posts: 10128
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This might be deviating from the above post, but I found this article here on overriding equals to be of great help.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!