Friday, June 16, 2017

Re: how to avoid JSNI

Maybe jsinterop.base library has some utility methods for cross casting.

Otherwise your options probably are (all untested):

1.) create a JavaScript file with a function that creates the array, then use JsInterop to call that function. 

2.) If you want it to be more generic and super unsafe you can probably also write something like:

In utils.js:

.apputils.reinterpret = function(o) {
return o;

In Java:

public static native <I, O> O reinterpret(I object);

byte[] bytes = reinterpret(new Int8Array(8));

This should allow you to reinterpret any java type without any cast checking by GWT.

3.) If you don't want to create an external JavaScript file then you probably have to try casting, e.g.

public byte[] createFastInt8(int size) {
return (byte[]) (Object) new Int8Array(size);

-- 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
To post to this group, send email to
Visit this group at
For more options, visit

No comments:

Post a Comment