Wednesday, August 23, 2017

Re: ClassCastException in generics



On Wednesday, August 23, 2017 at 1:29:51 PM UTC+2, Kirill Prazdnikov wrote:
Is the FileReader "instanceof $wnd.FileReader"? (Walk up the chain)

What is interesting, FileReader created with JSNI is not isInstanceOfFileReader, 

public static native FileReader newFileReader() /*-{
return new FileReader();
}-*/;

but FileReader created with jsType and jsConstructor is isInstanceOfFileReader

 @JsType(isNative = truepublic class FileReader { public FileReader() {} };

  isInstanceOfFileReader(fileReader) = true
  isInstanceOfFileReader(fileReader2) = false

The same for ArrayBuffer, one created with JSNI not a buffer passing isInstanceOfArrayBuffer, but one created with "new ArrayBuffer(10)" form java is passing isInstanceOfArrayBuffer.

Both FileReaders can read files and both ArrayBuffer returned form reading IS NOT passing isInstanceOfArrayBuffer.

Using your JSNI above, the objects are created in an iframe (the one the *.nocache.js creates and then loads *.cache.js into); the ones from JsInterop are (correctly/expectedly) created in the HTML host page.
As Tony said, use $wnd.FileReader rather than FileReader (or better yet, use JsInterop).

--
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