开发者

Working with EnumSet class in GWT

开发者 https://www.devze.com 2022-12-25 09:09 出处:网络
I am having trouble using EnumSet on the client side. I get this runtime error message: java.util.EnumSet.EnumSetImpl is not default instantiable (it must

I am having trouble using EnumSet on the client side.

I get this runtime error message:

java.util.EnumSet.EnumSetImpl is not default instantiable (it must have a zero-argument constructor or no constructors at all) and has no custom serializer.

Is this is a known issue?

Here is what I am doing (basically a hello world app)

开发者_运维百科Service:

String echo (EnumSet<Names> name) throws IllegalArgumentException;

Client:

echoServ.echo (EnumSet.of(Names.JOHN), new AsyncCallback<String>()
{ ....... });

Shared enum class enum Names { JOHN, NUMAN, OBAMA }


This is a GWT limitation - See http://code.google.com/p/google-web-toolkit/issues/detail?id=3028

The simplest workaround is to use a HashSet until that is fixed


It seems the problem is that EnumSet is not serializable according to GWT's rules:

  1. It is assignable to IsSerializable or Serializable, either because it directly implements one of these interfaces or because it derives from a superclass that does
  2. All non-final, non-transient instance fields are themselves serializable, and
  3. As of GWT 1.5, it must have a default (zero argument) constructor (with any access modifier) or no constructor at all.

See the docs for more info.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号