0

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 

クライアント側のコードでこのエラーが発生します。私がインターネットから読むことができるものは何でも、実行時にJavascriptにコンパイルされるため、JREコンテナーで実行されるすべての標準メソッドをGWTにエミュレートできないと言っています。しかし、私は経験が浅すぎてこのエラーを理解できません。これに関する助けをいただければ幸いです!

4

2 に答える 2

1

3 つの格言:

  • 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;
}

String にはすでに独自のシリアル化コーデック (つまり、コーダー/デコーダーまたはマーシャラー/デマーシャラー) があるため、コンパイラーは a と b を通過します。整数も同様です。

次に、コンパイラは、Cobweb が独自のコーデックを提供することによって Serializable を実装しているか、または Cobweb が次のような Serializable メンバーを含んでいるかどうかを確認しようとします。

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シリアル化可能とはどういう意味ですか?

Serializable を十分に実装していませんか? Google が新しい Serializable インターフェイスを実装しているのはなぜですか? いいえ。これは Google のせいですが、Google のせいではありません。

GWT UI Java は、実行前に常に Javascript にコンパイルされます。GWT UI Java のネイティブ コードは Javascript であり、バイナリ Java バイトコードではありません。ブラウザは Javascript のみを実行し、Java バイトコードは実行しないという明白な理由があります。

バイナリ データと GWT

ほとんどの場合、Serializable を実装すると、クラス GWT がシリアライズ可能になります。GWT でシリアライズ可能であるということは、必要に応じてコーデックを実行するために GWT によって生成された Javascript コードが存在することを意味します。つまり、コーデックは Java バイトコードではなく Java ソースにあります。GWT のシリアライゼーション/デシリアライゼーションはブラウザーで実行されるため、コーデックは Javascript に変換可能である必要があります。

ただし、GWT にまだコーデックがないクラスが多数あります。たとえば、GregorianCalender と、Reflection を必要とするほとんどのクラスです。GregorianCalender は Serializable を実装していますが、GWT コンパイラには、Javascript に変換できる Java ソース コードのコーデックがありません。

GWT で生成された Javascript は、ランタイム リフレクションを実行できません。そのため、GWT は、使用できる可能性のあるすべてのコードのコンパイル済み順列の遅延バインディングを実行することで、その欠点を補います。GregorianCalendar は何らかのリフレクションを実行し、GregorianCalendar 用の GWT コーデックを作成すると、Javascript コードの順列が膨大になりすぎると思います。それが理由であり、多くのクラスでコーデックが存在しない理由でもあると思います。誰か私を訂正してください。

元の質問に戻ります....

java.util.LinkedList.Node<E>

では、念のため、E とは一体何なのでしょうか? E を GWT シリアライズ可能に置き換えましたか?

スタック トレースからの証拠 (スタック トレースのトレースが得意な場合) は、ジェネリック引数を実際の型に置き換えることさえ気にしなかったことを示しています。そうすることで、GWT コンパイラーに E をクラス Object と見なさせることになります。そして、クラス Object をシリアル化する方法を誰も知りません。あなたは、創世記 41 章のファラオがヨセフにこう言ったようなものです。

「ジョセフ、私の夢を解釈してください。でも私は夢を忘れてしまったので、私の夢についても教えてください。」

于 2012-07-18T05:00:03.517 に答える
0

スタックの最初の行にあるように、シリアル化するには、クラスにパラメーターのないコンストラクターまたはカスタム シリアライザーが必要です。 ここの java-custom-serializationは、シリアライザの記述に関するトピックです

于 2012-07-17T06:00:35.990 に答える