Tuesday, August 22, 2017

Re: ClassCastException in generics

I have a base class for drag and drop logic which looks something like this 

public abstract class FileDropHandler<FileT> extends InputClientAdapter {
 // here we have some common UI logic and constuctor
 // and the following methods are platform specific:
  protected abstract int length(FileT arrayBuffer);
  protected abstract Async<String> doUpload(FileT arrayBuffer);
protected abstract void processFile(DropEvent<?> dropEvent, MouseEvent mouseEvent);
protected abstract ObjectFactory[] loadObjects(String file, FileT arrayBuffer);
}

So in case of web, FileT is ArrayBuffer which I get form dropEvent.file, which is a web File type used in drag events.

public class FileDropHandlerGwt extends FileDropHandler<ArrayBuffer> { ... };

For JVM version I have regular files so I use java.io.File for the template argument. 
public class FileDropHandlerJvm extends FileDropHandler<File> { ... };

And this does not work for me. 
As a workaround I currently have a class container for ArrayBuffer like

static class ArrayBufferContainer { public final ArrayBuffer buffer; };

which I use for template argument currently. 

I think that there is a way to use ArrayBuffer directly, But I have not found a way to do that.
In order to understand GWT and understand JS-interop I`m asking this here.


Thanks
 -Kirill

вторник, 22 августа 2017 г., 15:13:46 UTC+3 пользователь Vassilis Virvilis написал:
Kirill,

I am out of suggestions for but my curiosity drives me crazy.

What are you trying to do in java terms? For example:

  • Are you try to return an ArrayBuffer from a function: public <T> T getBuffer();
  • Are you try to pass an ArrayBuffer as a parameter: public <T> void sendBuffer(T buffer);
  • Are you try to put the ArrayBuffer in a List, Array, Set?
  • Something else?

I looked but I didn't find in the thread the description of the java caller that throws the exception.


On Tue, Aug 22, 2017 at 3:04 PM, Kirill Prazdnikov <pki...@gmail.com> wrote:
Sorry, copypaster error, here is the fixed

getType(buffer) = [object ArrayBuffer]
typeOf(buffer) = object


вторник, 22 августа 2017 г., 15:02:49 UTC+3 пользователь Kirill Prazdnikov написал:
Here it is:

getType(buffer) = [object ArrayBuffer]
typeOf(buffer) = [object ArrayBuffer]

private native String getType(Object x) /*-{
return Object.prototype.toString.call(x);
}-*/;

private native String typeOf(Object x) /*-{
return typeof x;
}-*/;


понедельник, 21 августа 2017 г., 21:47:37 UTC+3 пользователь Tony BenBrahim написал:
Take the object you get back from the file reader and run it through the JSNI method below and GWT,log the result. .Let's see if it really is an ArrayBuffer.(I would note the FileReader result is sometimes a String and sometimes an ArrayBuffer).
private native String getType(Object x)/*-{      return Object.prototype.toString.call(x);  }-*/  

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