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

我尝试编译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 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 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 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 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 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 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 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 has no available instantiable subtypes. [ERROR] subtype java.util.LinkedList.Node 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。
  • 实现Serializable可能不是GWT Serializable

只要它实现Serializable,可以序列化任何东西吗?

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

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

编译器将在a和b中航行,因为,String已经有自己的序列化编解码器(即编码器/解码器或编组器/解码器)。 整数也是如此。

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

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

d和e都已经具有序列化编解码器,这是由Sun / Oracle对Java语言的管理提供的。

如果CobWeb允许generics参数怎么办?

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

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

但是,除非Donkey具有自定义序列化编解码器,否则编译器会在以下内容中出现问题

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

GWT可串行是什么意思?

是不是足够实现Serializable? 为什么Google会实施新的Serializable接口? 不。 这是谷歌的错,但不是谷歌的错。

GWT UI Java总是在运行之前编译为Javascript。 GWT UI Java的本机代码是Javascript而不是二进制Java字节码。 显而易见的原因是浏览器只运行Javascript但不运行Java字节码。

二进制数据和GWT

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

但是,有许多类,GWT已经没有编解码器。 例如,GregorianCalender和大多数需要reflection的类。 GregorianCalender实现了Serializable,但GWT编译器在Java源代码中没有任何编解码器可以转换为Javascript。

GWT生成的Javascript无法运行时reflection。 因此,GWT通过对您可以使用的所有可能代码的预编译排列执行延迟绑定来补偿该缺陷。 我相信GregorianCalendar会执行一些reflection测量,并且为GregorianCalendar写一个GWT编解码器将会有太多的Javascript代码排列。 我相信这也是导致许多课程缺少编解码器的原因。 有人请指正。

回到原来的问题 ….

 java.util.LinkedList.Node 

所以,为了善良,世界上的E是什么? 你用GWT序列化代替E了吗?

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

“约瑟夫请解释我的梦想,但我已经忘记了我的梦想,所以你也必须告诉我我的梦想。”

作为第一行堆栈说,要序列化,类需要具有没有参数的构造函数或具有自定义序列化程序。 java-custom-serialization这里是关于编写序列化器的主题