Just removing the final keyword does not work. It still complains about the
initialization. I cannot remove the initialization because that is not
valid Java.
The @JsOverlay solution looks OK. This line of Java
ctx.fillText("Canvas is an element node: " + (canvas.getNodeType() ==
Node.ELEMENT_NODE), 10, 20);
compiles to this line of Javascript
ctx.fillText('Canvas is an element node: ' + (canvas.nodeType == 1), 10,
20);
There does not seem to be any overhead from the overlay. It would have been
nicer if it said (canvas.nodeType == Node.ELEMENT_NODE) in Javascript. But
it evaluates to the same, so I am happy.
Den fredag den 4. december 2015 kl. 06.28.02 UTC+1 skrev Goktug Gokdogan:
>
> Ignoring initialization is quite complicated when you put in to account
> generated clinit and also primitives which becomes compile-time-constants
> per jls and automatically inlined. Also code wise it is quite weird and
> potentially confusing.
>
> Workaround is quite simple, just remove the "final" keyword and you are
> set.
>
>
> On Thu, Dec 3, 2015 at 5:35 AM, Jens <[email protected] <javascript:>>
> wrote:
>
>>
>> Awesome. Thank you. @JsOverlay did the trick.
>>>
>>
>> But IMHO @JsOverlay is only a workaround because it is meant to be used
>> for code additions that do not exist in the underlying native type. So in
>> your case GWT will now generate some additional code for your constants and
>> will not use $wnd.Node.ELEMENT_NODE when doing comparisons. The link Thomas
>> has posted is a good example of proper JsOverlay usage as the constant
>> "TAG" is not part of the underlying native object.
>>
>> So I would consider it a bug/missing feature that you can not define
>> native constants in a native JsType. IMHO the restriction checker should
>> allow static final constant initialization in native JsType and if constant
>> is not annotated with @JsOverlay then GWT should treat the constant name as
>> native constant. The value to initialize the constant in java code should
>> be ignored, as initialization only exists to make java happy.
>>
>> cc @goktug
>>
>> -- J.
>>
>
>
--
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 http://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.