Friday, January 27, 2017

Re: GWT 2.7: access public static final field in JSNI results as undefined in SuperDevMode

I would say it's a bug (have you tried in 2.8, maybe it's fixed?).
I'd also say one should try to keep JSNI as small as possible; your method could be rewritten as:
public static void doSomethingWithMarker() {
private static native void nativeDoSomethingWithMarker(String cm) /*-{

In legacy devmode, JSNI boundaries used to be a performance issue, but this is no longer the case with SuperDevMode, so there's no reason to write big JSNI methods (or even JSNI at all: use JsInterop; there are still a few cases that need JSNI, but one can do almost everything with JsInterop nowadays).

On Friday, January 27, 2017 at 11:23:35 AM UTC+1, Norbert Bartels wrote:

Hi all,

during development I ran into a problem and I had to dig a bit deeper to find the root cause. Perhaps someone can explain why this happens.

I use GWT 2.7. And I have a class with some constants. For example something like this:

public class MyConstants {      public static final String SPECIAL_MARKER = "marker";    }  

Now I try to use this in a JSNI method in another class, for example in this way:

...    public static native void doSomethingWithMarker() /*-{     var cm = @my.package.MyConstants::SPECIAL_MARKER      $wnd.alert(cm);  }-*/;    ...  

In classic dev mode and in the compiled version this is working. In SuperDevMode cm is undefined.

Now, I remove the final and voila, it even works in SuperDevMode.
So obviously the final is a problem. But why is it working in classic and compiled mode? Is this simply a bug or is there a better way to use such constants?


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