Javascript JNI 覆盖类型中 Long 的 GWT 问题
我在将 JSON 转换为 JNI 覆盖类型时遇到问题。 java代码必须遵循以下方法:
long nr = 10l;
public Long getNr() {
return nr;
}
JNI覆盖类型是:
public final native Long getNr() /*-{
return this.nr;
}-*/;
我避免在覆盖类型中使用长原语进行操作,因为编译器不允许这样做。官方文档说这效率低下,但应该可行。但是,我得到:
java.lang.IllegalArgumentException: Something other than a Java object was returned from JSNI method '@com.avaya.thunder.portal.client.shared.model.Customer::getNr1()': JS value of type int, expected java.lang.Object
at com.google.gwt.dev.shell.JsValueGlue.get(JsValueGlue.java:178)
at com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:271)
我正在使用 GWT 2.2.0。
难道是我做错了什么?这应该有效吗?任何帮助表示赞赏。 谢谢。
I'm having a problem with the conversion of a JSON to a JNI overlay type.
The java code has to following method:
long nr = 10l;
public Long getNr() {
return nr;
}
The JNI overlay type is:
public final native Long getNr() /*-{
return this.nr;
}-*/;
I'm avoiding operating with the long primitive in the overlay type, as the compiler doesn't allow it. The official documentation says that this is inefficient but it should work. However, I'm getting:
java.lang.IllegalArgumentException: Something other than a Java object was returned from JSNI method '@com.avaya.thunder.portal.client.shared.model.Customer::getNr1()': JS value of type int, expected java.lang.Object
at com.google.gwt.dev.shell.JsValueGlue.get(JsValueGlue.java:178)
at com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:271)
I'm using GWT 2.2.0.
Is it something I'm doing wrong? Should this work? Any help is appreciated.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果你想取出一个 Long 对象,你需要放入一个 Long 对象:
不幸的是,这意味着 'nr' 在 JavaScript 中将是一个不透明的对象。通常,如果我们想在 JS 和 Java 中操作一个数字,我们会传递“double”原语。这样就不会出现意外(Java 原始 double 直接映射到 Js 类型 Number)。
You need to put in a Long object if you want to get one out:
Unfortunately, that means that 'nr' will be an opaque object in JavaScript. Usually, we pass around 'double' primitives if we want to manipulate a number in both JS and Java. That way there are no surprises (Java primitive double maps directly to Js type Number).