Problems with anonymous class and serializable

79 views
Skip to first unread message

saburo...@gmail.com

unread,
Aug 13, 2007, 4:20:18 AM8/13/07
to Google Web Toolkit
I stumped across this problem when I try to declare an anonymous class
within my class which is meant to be serializable. Have anyone
stumbled across this, or found any solution for it ?

Rebinding com.gwt.core.client.RPCService
Invoking <generate-with
class='com.google.gwt.user.rebind.rpc.ServiceInterfaceProxyGenerator'/
>
Analyzing serializability for 756 types
The following types were determined to be unserializable:
com.gwt.core.client.Record.1
Is local
com.gwt.core.client.Record.2

Thank you very much and have a nice day

saburo...@gmail.com

unread,
Aug 13, 2007, 10:16:34 PM8/13/07
to Google Web Toolkit
I know that it's unacceptable to marshall an anonymous class thru RMI,
but is there a design workaround for this ?
I don't want to create multiple number of classes just to refactor my
anonymous classes. The reason for the anonymous classes to be there is
for something like a custom enum.

Thank you very much and have a nice day.

On Aug 13, 4:20 pm, "saburo.ok...@gmail.com" <saburo.ok...@gmail.com>
wrote:

Andrés Testi

unread,
Aug 13, 2007, 11:49:07 PM8/13/07
to Google Web Toolkit
If you have an anonymous class like this:

Closure myClosure = new Closure(){...};

You can extend the Closure interface, extending IsSerializable too:

interface SerializableClosure extends Closure, IsSerializable{}

Then, you can use SerializableClosure instead of Closure to
instantiate your anonymous class:

Closure myClosure = new SerializableClosure(){ .... }

I think this can work ;)

On 13 ago, 23:16, "saburo.ok...@gmail.com" <saburo.ok...@gmail.com>
wrote:

saburo...@gmail.com

unread,
Aug 14, 2007, 12:04:03 AM8/14/07
to Google Web Toolkit
Nope, it doesn't work. Since I guess that anonymous class can't be
resolved when RPC-ed over. Have no idea about the technical
explanation

Andrés Testi

unread,
Aug 14, 2007, 12:32:33 AM8/14/07
to Google Web Toolkit
Oh, sorry, this can be a GWT Compiler/Generator API limitation :(

On 14 ago, 01:04, "saburo.ok...@gmail.com" <saburo.ok...@gmail.com>
wrote:

Ian Petersen

unread,
Aug 14, 2007, 12:53:08 AM8/14/07
to Google-We...@googlegroups.com
Can't you just "promote" the anonymous class to be a named inner class?

From this:

public class Foo {

public Interface aMethod() {
return new Interface() {
// blah blah
};
}
}

To this:

public class Foo {

public static final class InterfaceImpl implements Interface {
// blah blah
}

public Interface aMethod() {
return new InterfaceImpl();
}
}

?

If you make the named class an inner class, it has to be a static
class or the compiler will generate an error that it's not
serializable.

Ian

--
Tired of pop-ups, security holes, and spyware?
Try Firefox: http://www.getfirefox.com

saburo...@gmail.com

unread,
Aug 14, 2007, 12:58:02 AM8/14/07
to Google Web Toolkit
Well, that's the original method. But, we wanted to strive for
something more elegant, without cluttering the class, with numerous
inner classes.

But nevermind, I guess implementing the classes themselves explicitly
is the only way for resolving this problem.

Thanks a lot guys ! ~(_8^(I)

Reply all
Reply to author
Forward
0 new messages