gpt4 book ai didi

java.util.LinkedList.Node 无法分配给 GWT Serialized?

转载 作者:行者123 更新时间:2023-12-01 15:16:36 27 4
gpt4 key购买 nike

当我尝试编译 GWT 应用程序时,出现许多错误。其中一些是

[ERROR] com.google.gwt.xml.client.impl.AttrImpl is not default instantiable (it must have a zero-argument constructor or no constructors at all) and has no custom serializer. 
[ERROR] com.google.gwt.xml.client.impl.CDATASectionImpl is not default instantiable (it must have a zero-argument constructor or no constructors at all) and has no custom serializer.
[ERROR] com.google.gwt.xml.client.impl.CommentImpl is not default instantiable (it must have a zero-argument constructor or no constructors at all) and has no custom serializer.
[ERROR] com.google.gwt.xml.client.impl.DocumentFragmentImpl is not default instantiable (it must have a zero-argument constructor or no constructors at all) and has no custom serializer.
[ERROR] com.google.gwt.xml.client.impl.DocumentImpl is not default instantiable (it must have a zero-argument constructor or no constructors at all) and has no custom serializer.
[ERROR] com.google.gwt.xml.client.impl.ElementImpl is not default instantiable (it must have a zero-argument constructor or no constructors at all) and has no custom serializer.
[ERROR] com.google.gwt.xml.client.impl.EntityReferenceImpl is not default instantiable (it must have a zero-argument constructor or no constructors at all) and has no custom serializer.
[ERROR] com.google.gwt.xml.client.impl.NamedNodeMapImpl is not default instantiable (it must have a zero-argument constructor or no constructors at all) and has no custom serializer.
[ERROR] com.google.gwt.xml.client.impl.NodeImpl is not default instantiable (it must have a zero-argument constructor or no constructors at all) and has no custom serializer.
[ERROR] com.google.gwt.xml.client.impl.NodeListImpl is not default instantiable (it must have a zero-argument constructor or no constructors at all) and has no custom serializer.
[ERROR] com.google.gwt.xml.client.impl.ProcessingInstructionImpl is not default instantiable (it must have a zero-argument constructor or no constructors at all) and has no custom serializer.
[ERROR] com.google.gwt.xml.client.impl.TextImpl is not default instantiable (it must have a zero-argument constructor or no constructors at all) and has no custom serializer.
[ERROR] java.util.AbstractList.SubList<E> is not default instantiable (it must have a zero-argument constructor or no constructors at all) and has no custom serializer.
[ERROR] java.util.AbstractList.SubList<E> is not default instantiable (it must have a zero-argument constructor or no constructors at all) and has no custom serializer.
[ERROR] java.util.Collections.UnmodifiableList<T> is not default instantiable (it must have a zero-argument constructor or no constructors at all) and has no custom serializer.
[ERROR] java.util.Collections.UnmodifiableList<T> is not default instantiable (it must have a zero-argument constructor or no constructors at all) and has no custom serializer.
[ERROR] java.util.Collections.UnmodifiableRandomAccessList<T> is not default instantiable (it must have a zero-argument constructor or no constructors at all) and has no custom serializer.
[ERROR] java.util.Collections.UnmodifiableRandomAccessList<T> is not default instantiable (it must have a zero-argument constructor or no constructors at all) and has no custom serializer.
[ERROR] java.util.LinkedList.Node<E> is not assignable to 'com.google.gwt.user.client.rpc.IsSerializable' or 'java.io.Serializable' nor does it have a custom field serializer
[ERROR] java.util.LinkedList.Node<E> has no available instantiable subtypes.
[ERROR] subtype java.util.LinkedList.Node<E> is not assignable to 'com.google.gwt.user.client.rpc.IsSerializable' or 'java.io.Serializable' nor does it have a custom field serializer

我在客户端代码中收到此错误!从我从互联网上读到的内容来看,它说我根本无法将 JRE 容器中运行的所有标准方法模拟为 GWT,因为它将在运行时编译为 Javascript。但我太缺乏经验,无法理解这个错误。对此有任何帮助将不胜感激!

最佳答案

三大格言:

  • GWT Java 是 Java,但不是 Java
  • GWT Java 实际上是 Java 编译器友好的 Javascript。
  • 实现可序列化可能不是 GWT 可序列化

Can anything be serialized as long as it implements Serializable?

在 java SE/EE 字节码世界中,序列化更简单。在下面的类声明中:

class Spider
implements Serializable{
String a;
Integer b;
Cobweb c;
}

编译器会通过a和b,因为String已经有自己的序列化编解码器(即编码器/解码器或编码器/解码器)。整数也是如此。

编译器然后尝试查看 Cobweb 是否通过提供自己的编解码器来实现 Serialized,或者 Cobweb 是否包含 Serialized 成员,例如

class Cobweb 
implements Serializable{
Boolean d;
Double e;
}

d 和 e 都已经拥有由 Sun/Oracle 的 Java 语言管理机构提供的序列化编解码器。

如果 CobWeb 允许通用参数怎么办?

class Cobweb <T>
implements Serializable{
Boolean d;
T e;
}

Cobweb<Float>是可序列化的,因为 Java 已经有一个 Float 的序列化编解码器。

但是,除非 Donkey 有自定义序列化编解码器,否则编译器会发出以下警告

class Spider
implements Serializable{
String a;
Integer b;
Cobweb<Donkey> c;
}

GWT 可串行化是什么意思?

实现序列化还不够吗?为什么 Google 正在实现新的 Serialized 接口(interface)?没有。这是谷歌的错,但又不是谷歌的错。

GWT UI Java 在运行之前始终会编译为 Javascript。 GWT UI Java 的 native 代码是 Javascript,而不是二进制 Java 字节码。显而易见的原因是浏览器只运行 Javascript,而不运行 Java 字节码。

Binary Data and GWT

在大多数情况下,实现可序列化将使您的类 GWT 可序列化。 GWT 可序列化意味着存在 GWT 生成的 Javascript 代码,可以在需要时执行编解码器。即,编解码器是 Java 源代码而不是 Java 字节码。编解码器必须可翻译为 Javascript,因为 GWT 序列化/反序列化在浏览器上运行。

但是,GWT 有很多类还没有编解码器。例如,GregorianCalender 和大多数需要反射的类。 GregorianCalender 实现了 Serialized,但 GWT 编译器在可翻译为 Javascript 的 Java 源代码中没有任何编解码器。

GWT 生成的 Javascript 无法进行运行时反射。因此,GWT 通过对您可以使用的所有可能代码的预编译排列执行延迟绑定(bind)来弥补这一缺陷。我相信 GregorianCalendar 会执行一些反射措施,并且为 GregorianCalendar 编写 GWT 编解码器会导致 Javascript 代码的排列数量过多。我相信这就是原因,也是许多类缺少编解码器的原因。请有人纠正我。

回到原来的问题 ....

java.util.LinkedList.Node<E>

那么,老天爷,E 到底是什么?您是否用 GWT 可序列化替换了 E?

来自堆栈跟踪的证据(如果我擅长跟踪堆栈跟踪)表明您甚至没有费心用实际类型替换泛型参数。通过这样做,您将强制 GWT 编译器将 E 视为类 Object。没有人知道如何序列化 Object 类。你会像创世记 41 章中的法老告诉约瑟,

"Joseph please interpret my dream, but I have forgotten my dream, so you have to tell me about my dream too."

关于java.util.LinkedList.Node<E> 无法分配给 GWT Serialized?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11516675/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com