Monday, January 15, 2018

Re: @FunctionalInterface VS @JsFunction

Yeah sure, there are many workarounds...which leads to bloat as shown.
Then my request would be to by default have Runnable and Callable in gwt java emulation to be attributed by default with interop.JsFunction :-)

Regards Jan

On Monday, January 15, 2018 at 4:11:45 PM UTC+1, Thomas Broyer wrote:

On Monday, January 15, 2018 at 4:03:11 PM UTC+1, Jan Blok wrote:

Would it be possible for GWTc to handle java.lang.FunctionalInterface as if it was jsinterop.annotations.JsFunction ?

No, if only because JsFunction has many constraints:
The reason for asking is, I have this java code:

    public void transaction(Runnable runnable) {
        try {
        finally {

when I expose this method via jsinterop I get a warning "not usable from javascript"

I intent to use it from JS/TS as: myJavaLib.transaction(() => doSomethingInTransaction(...));

but this is not possible unless I supersource java.lang.Runnable and add @JsFunction 

You'd need to create an overload taking a JsFunction as input, and exposing that one.

@JsFunction @FunctionalInterface
interface TransactionCallback {
void run();

public void transaction(TransactionCallback callback) {
try {
} finally {

// Note: not a @JsMethod
public void transaction(Runnable runnable) {
((TransactionCallback) runnable::run);

It seems to me that @FunctionalInterface and @JsFunction are very similar already...

And this is why the javadoc for JsFunction recommends also annotating the interface with FunctionalInterface. 

You received this message because you are subscribed to the Google Groups "GWT Users" 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