On Fri, May 29, 2009 at 11:31 AM, Vitali Lovich <[email protected]> wrote:

> The way you get a method reference in pure Java is via reflection, which in
>> general is not feasible though there have been some discussions of allowing
>> it when everything can be evaluated at compile time (ie, all constants for
>> classes and method/field names) -- even that seems to be a long way away
>> however.
>>
> How about through GWT.create?  Then it uses reflection to supply the actual
> function.  Might be limited to JSNI functions unless you can compile code
> fragments.
>
>>
GWT.create takes a single class literal, so there is no way to describe a
method.  You could have it generate an object with a callback function, but
that is going to be a lot more boilerplate than just having a simple JSNI
method that returns the torn-off function.


> I haven't actually looked at the plugin yet.
>

If you are worried about JSNI syntax or autocompletion, you really should.
You also get a "Deploy to Google" button for AppEngine integration.


> Why not create a JsFunction class that extends from JavaScriptObject to
> represent a JS lambda function.
>
> However, since you can't have polymorphic dispatch on JSOs, that would
>> reserve whatever name was chosen from all subclasses, so it would have to be
>> something unlikely to collide.
>>
>
> I'm not sure what you mean here.  Why would you need to reserve a name?
>

Because of how JSOs work (in that you can freely cast them to each other),
JSO method calls have to be statically resolvable.  If we put a call()
method on JavaScriptObject, no other JSO subclass could have a call method
with the same signature (and that restriction is enforced by requiring the
method or class to be final).  However, your suggestion of putting it on a
JSO subclass solves that problem.

The remaining complication is that you can't declare a JSNI method with
varargs, so it is somewhat complicated to build the args list for the call.
You would probably also have to have one for void returns and one for calls
returning a value (it might be possible to handle that with a return type
parameter on JsFunction like JsFunction<Int>).

-- 
John A. Tamplin
Software Engineer (GWT), Google

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

Reply via email to