Wednesday, October 22, 2025

@JsFunction producing ClassCastException

Hello,
I'm working on updating/migrating the gwtbootstrap3 library
  • updating all external Javascript libraries
  • migrating to JsInterop (get rid of jsni)
  • migrating to Bootstrap 5
But I'm facing an issue with the following @JsFunction

import jsinterop.annotations.JsFunction;

@JsFunction
@FunctionalInterface
public interface FormatterCallback<T> {
String formatTooltip(T value);
}

When I declare it with lambda it fails
// using @JsFunction
slider.setFormatter(range -> "Range: [" + range.getAt(0) + "," + range.getAt(1) + "]");

But if I declare it with JSNI it works
slider.setFormatter(rangeFormatter());

private native FormatterCallback<Range> rangeFormatter() /*-{
return function (value) {
return "Range: [" + value[0] + "," + value[1] + "]";
};
}-*/;

You can find the successful and the failing GWTTestCase here:


When I log in the console the 2 functions it looks like that

===JSNI===
ƒ (value_0_g$){
    return 'Range: [' + value_0_g$[0] + ', ' + value_0_g$[1] + ']';
  }

===JsFunction===
ƒ (){
    return samMethod_0_g$.apply(lambda_0_g$, arguments);
  }

Any idea how to resolve it?
thanks

--
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/f5682bbf-baac-4d87-a7ac-bd4499a7abefn%40googlegroups.com.

No comments:

Post a Comment