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: >> >> Hi, >> >> 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: > http://www.gwtproject.org/javadoc/latest/jsinterop/annotations/JsFunction.html > > >> The reason for asking is, I have this java code: >> >> public void transaction(Runnable runnable) { >> startTransaction(); >> try { >> runnable.run(); >> } >> finally { >> endTransaction(); >> } >> } >> >> 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(); > } > > > @JsMethod > public void transaction(TransactionCallback callback) { > startTransaction(); > try { > callback.run(); > } finally { > endTransaction(); > } > } > > // Note: not a @JsMethod > public void transaction(Runnable runnable) { > transaction((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 [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/google-web-toolkit. For more options, visit https://groups.google.com/d/optout.
