For some client-server user code in GWT, I would like to dynamically implement a Java interface similar to the way this will be done using java.lang.reflect.Proxy. Since GWT does not contain reflection support, and I don’t want to write a clumsy code generator, I wonder if this can be done using the JSNI and Overlay types.
I am thinking of the following lines:
- I have some existing java interface and somehow represent its methods and their signatures, annotations, etc. (since the actual class object will not have any help in GWT).
- I pass this view to some JSNI method that uses it to create a new Javascript object and define the appropriate methods on it. The actual implementation of the methods is pretty trivial, they just write their arguments to some data structure and return null.
- I get a Javascript object from JSNI that somehow depends on the type of interface. When methods from the interface are called in this instance, the corresponding Javascript method that was defined in step 2 is called and saves the arguments.
Has anyone tried something like this? Are there reasons why this will not work in principle?
Thanks in advance.
source
share