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.
>
>
> An event handler's return type is used to cancel the event (
> https://blog.ltgt.net/html-event-handlers/#return-value / 
> https://html.spec.whatwg.org/multipage/webappapis.html#the-event-handler-processing-algorithm),
>  
> but for that specific event it doesn't matter as it's not cancelable anyway 
> (
> https://html.spec.whatwg.org/multipage/browsing-the-web.html#updating-the-document:popstateevent
> )
>

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

Reply via email to