Sunday, August 20, 2017

Re: ClassCastException in generics

On Friday, August 18, 2017 at 4:01:47 PM UTC+2, Kirill Prazdnikov wrote:
Hi, I`m always getting ClassCastException if I use @JsType(isNative = true) object as a generic template argument. 

Is it possbile to do something with that ?
Is it possbile to avoid check-cast generation if the generic is used with @JsType type ?

Think about what this means.

@JsType(isNative=true) applied to a class is strictly equivalent to @JsType(isNative=true, namespace="", name="Foo"), which means, literally: "this Java class is an "interop mapping" to be able to work with the JS "class/type" from Java code". This implies that you expect instances of that class to be "instanceof" (in JS), and btw such an "instanceof" in Java will literally translate to that same "instanceof" in JS.

If you do not intend to create instances of that Java type, then you can use a Java interface and use namespace=GLOBAL,name="?" (see note in
If you want to use a Java class and/or need to create instances (but do not have to use a specific JS constructor), then you'll want to use namespace=GLOBAL,name="Object".

But as Tony said, you do not want to disable cast-checking. If you think you need to do it, then you're most likely doing it wrong.

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