Tuesday, August 30, 2011

Wanted: Missing Interface - Is the GWT compiler too aggressive?

Hi all,

I have the following:

interface Api {
void api();
}
interface Init {
void init();
}
class Impl implements Api, Init {
void api() { ... }
void init() { ... }
}

In the GWT module:

<module ...>
<inherits .../>
<replace-with class="impl.Impl">
<when-type-is class="api.Api"/>
</replace-with>
...
</module>

I then use the above like this:

Api api = GWT.create(Api.class); // This correctly returns an instance of Impl.
((Init) api).init();

This fails with a ClassCastException:

java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.google.gwt.dev.shell.ModuleSpace.onLoad(ModuleSpace.java:396)
at com.google.gwt.dev.shell.OophmSessionHandler.loadModule(OophmSessionHandler.java:193)
at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:510)
at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:352)
at java.lang.Thread.run(Thread.java:662)
Caused by: java.lang.ClassCastException: impl.Impl cannot be cast to api.Init
at ...

Given that impl.Impl implements api.Init, this is rather strange. Was
the GWT compiler too aggressive? Did it remove the Init interface and
implementation "because it's not being used"? Or did I run into
something else and is the error message just overly cryptic?

Cheers,
Hilco

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To post to this group, send email to google-web-toolkit@googlegroups.com.
To unsubscribe from this group, send email to google-web-toolkit+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate