There's a type safe trick to doing it for all methods that return a value, see:

http://cromwellian.blogspot.com/2006_07_01_archive.html

which is based on this:

http://weblogs.java.net/blog/alexwinston/archive/2005/04/strongly_types_1.html

With my GWT.create() relaxation proposal, you could write a method like

lambda(Class).method()

and have it return a JsClosure that is invokable.

-Ray


On Sat, May 30, 2009 at 7:12 AM, Thomas Broyer <[email protected]> wrote:
>
>
>
> On 29 mai, 02:18, Vitali Lovich <[email protected]> wrote:
>> It would be nice if there was a way to wrap Java methods with an opaque
>> Javascript function object so that you could pass them around in the native
>> code (obviously there are issues with compiler optimizations in this case).
>> Ideally, you would be also able to execute any Javascript function object
>> from within Java code, although that does present some problems.
>>
>> Thoughts?
>
> You should be able to code something like this with a generator,
> resulting in code such as the following; but I'm not sure it really is
> worth it, compared to coding the same JSNI by hand...
>
> interface MyMethods extends Methods
> {
>   @Method("foo(I)")
>   JavaScriptObject foo(MyClass instance);
>
>   @StaticMethod(MyClass.class, "bar(Ljava/lang/String;)")
>   JavaScriptObject bar();
> }
>
> ...
> MyMethods methods = GWT.create(MyMethods.class);
> callSomeJSNI(methods.foo(myClassInstance));
> callSomeJSNI(methods.bar());
>
> Where the generator would build such an implementation:
> class MyMethodsImpl implements MyMethods
> {
>   public native JavaScriptObject foo(MyClass instance) /*-{
>      return function(arg0) { [email protected]::foo(I)
> (arg0); }
>   }-*/;
>
>   public native JavaScriptObject bar() /*-{
>      return @net.example.MyClass::bar(Ljava/lang/String;);
>   }-*/;
> }
>
> (where the bar() impl might require a wrapper function too)
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
http://groups.google.com/group/Google-Web-Toolkit-Contributors
-~----------~----~----~----~------~----~------~--~---

Reply via email to