Saturday, October 25, 2014

How to pass a function to a method defined with JsInterop

Hi all, I'm using GWT 2.7.0-beta and I'm experimenting an integration with some existing JavaScript.

I wrote a wrapper:

public interface ExistingJavaScriptObject {
ExistingJavaScriptObject function(String param, Object callback);

It's the same pattern used in many JS Frameworks and I need to pass a callback as the second param.

For that I wrote a SAM interface

@JsType(prototype = "Function")
public interface FunctionCall<P, R> {
R function(P param);

But I don't know how to create a function object from this if not with a trampoline method in JNSI:

private static native <P,R> JavaScriptObject i2f(FunctionCall<P, R> functionCall) /*-{
return function(param) {
return functionCall.@FunctionCall::function(Ljava/lang/Object;)(param);

I think I'm missing the point, here in GWT 2.7 I can't use lambdas so I think there must be a smarter way to pass a function to a wrapper JavaScript object.

Any hints ? No better options ??

Thank you.

You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
To post to this group, send email to
Visit this group at
For more options, visit

No comments:

Post a Comment