Wednesday, December 4, 2024

Re: GWT history with push state

Thank you Thomas and Colin.  Setting onpopstate with a lambda is perfect!

On Thursday, 5 December 2024 at 6:51:23 am UTC+11 Thomas Broyer wrote:
On Wednesday, December 4, 2024 at 5:10:32 PM UTC+1 Colin Alworth wrote:
Note that "@FunctionalInterface" is not required to express a Java interface with only one abstract method as a lambda. You can write:

DomGlobal.window.onpopstate = event -> {
    // Do something
    return null;
};

to use it as a lambda. This compiles for me with GWT 2.12.1 and Java 11.

Does it show that I haven't written that kind of code for quite some time? 😂
(and/or rely too much on my IDE)
 
The key is the "return null", missing in your example (and in Thomas's as well as a return type for the anon inner class). 

The return type is declared as Object, which may be an oversight in the original closure externs file, I don't see a way that an event handler can change anything by returning a different value. In JS, a missing return would implicitly return undefined, but Java requires an explicit return for non-void methods.

--
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 google-web-toolkit+unsubscribe@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/google-web-toolkit/f4c976e2-7b1c-458a-b680-388e55b92541n%40googlegroups.com.

No comments:

Post a Comment