GWT JSNI拆分方法的bug [英] GWT JSNI split method bug

查看:171
本文介绍了GWT JSNI拆分方法的bug的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个GWT应用程序,并且正在获取包含select查询结果的List。这个选择查询有行。每行,每个元素都与前一个和下一个由::分开。

我想用String.split分割它,但它需要很长时间去表演。我目前已经读过(我正在使用GWT 2.5.1),它的String.split方法非常麻烦,有时几乎比JSNI方法多执行1000倍;所以我采取了这种方法。



我使用的JSNI方法如下(我从这个网站上找到):

  public static final native String [] split(String string,String separator)/ *  -  {
return string.split(separator);
} - * /;

但现在,我收到这个错误:

java.lang.ClassCastException:com.google.gwt.core.client.JavaScriptObject $不能转换为[Ljava.lang.String;



即使我在最后写了一个.toString(),错误如下:



java.lang.ClassCastException:java.lang.String不能转换为[Ljava。 lang.String;

我打电话给这个方法:

  String [] temp = split(str,::); 

为了得到temp内部分割的结果,以备后用。



str它是一个包含iterator.next()的字符串。

请问我可能丢失或误解了什么



预先感谢您的时间,

亲切的问候,

解决方案

JavaScript列表不是的Java数组。虽然GWT使用JavaScript列表来模拟Java数组,但这并不意味着它们是相同的。



相反,您应该返回 JsArrayString ,并以此方式使用它,或者使用Java版本的String.split来返回一个真正的Java数组。


I am developing a GWT application and I am obtaining a List containing the result of a select query. This select query has rows. Each row, has each element separated from the previous and the next by "::".

I am trying to split it using String.split, but it is taking ages to perform. I have read that currently (i am using GWT 2.5.1), the String.split method its quite bugged, sometimes almost taking x1000 times more than the JSNI method to perform; so i took that approach.

The JSNI method that i am using is the following (which i picked up from this same site):

public static final native String[] split(String string, String separator) /*-{
   return string.split(separator);
   }-*/;

But now, i am getting this error :

java.lang.ClassCastException: com.google.gwt.core.client.JavaScriptObject$ cannot be cast to [Ljava.lang.String;

And even if I write a .toString() at the end, the error becomes the following:

java.lang.ClassCastException: java.lang.String cannot be cast to [Ljava.lang.String;

I am calling this method like this :

String[] temp = split(str, "::");

In order to get the results from the split inside temp, for later usage.

str it is a String containing an iterator.next().

Could you please tell me what could i be missing or misunderstanding?.

Thank you in advance for your time,

Kind regards,

解决方案

A JavaScript list is not a Java array. While GWT uses JavaScript lists to emulate Java arrays, that doesn't mean that they are the same thing.

Instead you should return JsArrayString from your method, and use it that way, or just use the Java version of String.split which returns a real Java array.

这篇关于GWT JSNI拆分方法的bug的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆