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:

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


In Java:

@JsMethod(namespace="apputils")
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 google-web-toolkit+unsubscribe@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at https://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment