Working with EnumSet class in GWT
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:
- 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
- All non-final, non-transient instance fields are themselves serializable, and
- 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.
精彩评论