• Post Reply Bookmark Topic Watch Topic
  • New Topic

anonymous inner class with rmi  RSS feed

 
Stephanie Smith
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a remote interface that has a method:
addObject(String, Object);
I know that Object must either be Serializable or a remote object. I attempted this using an anonymous inner class as:
addObject("someValue",
new ListenerInterface()
{
someMethod()
{
}
});
where the ListenerInterface is Serializable. If I'm calling
addObject on the remote reference to the object, then I get
the following exception because i'm using this anonymous inner class:
java.rmi.MarshalException: error marshalling arguments nested exception is:
java.io.NotSerializableException

It appears this occurs because the outter class that makes
this call is not Serializable. If this outter class is
Serializable, this call will work fine.
I can't find any documentation that discusses this behavior.
Any ideas on why it works this way?
thanks
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The reason you are getting NotSerializableException is that
inner classes implicitly get a reference to their outer class
with most compilers. Consequently serializing the inner class
tries to serialize the outer class. How it *may* work on some compiler/VM combinations.
Serializing inner classes is not recommended. Why? See:
http://java.sun.com/j2se/1.4/docs/guide/serialization/spec/serial-arch.doc10.html#4539
of the Java Object Serialization Specification.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!