• Post Reply Bookmark Topic Watch Topic
  • New Topic

should an interface implement Serializable

 
Puneet Agarwal
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I have an interface Foo which implements Seializable, is there a guarantee that the classes implementing that interface would also be Serializable?
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24213
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes.
 
Puneet Agarwal
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We are not observing that behavior in Weblogic 9.1 or Websphere 5.1.1.x . If we put an object of a class Bar on HttpSession, then failover does not work. class Bar implements interface Foo which imlements Serializable. Has anybody seen such a behavior ever
 
Carl Trusiak
Sheriff
Posts: 3341
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, if Class Bar encapsulates another object that doesn't implement Serializable, Bar can no longer be Serialized even though it extends Foo which extends Serializable.

In this example, an unserializable exception will be thrown on attempts to Serialize instances of Bar.
This can also occur if super classes of Bar contain such unserializable objects.
[ July 26, 2006: Message edited by: Carl Trusiak ]
 
Puneet Agarwal
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In our case the child class Bar does not declare any data members of its own. It is only inheriting from base class Foo. Base class Foo has data members which our Serializable.

Does this mean that for Bar to be Serializable we would have to explicityl declare it to be Serializable.
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24213
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No. It means that your base class probably has some non-serializable members.

Remember that whenever you're sure something should work, but it doesn't, then you're wrong. People too often forget this simple principle.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!