For converting a integer into an enum (out of a json file), I declared some HashMaps like this:
final static HashMap<Integer, Types> getType = new HashMap<Integer, Types>() {
{
put(1, Types.TYPE1);
put(2, Types.TYPE2);
....
}
};
Now eclipse gives me the following warning:
The serializable class does not declare a static final serialVersionUID field of type long
I already found a pretty good explanation for the error message here. However I don’t know how this is with GWT. Does GWT use the SerialVersionUID anywhere, or is it actually deleted by the closur compiler? As far as I see it, it isn’t needed.
serialVersionUIDis only used for Java serialization (using the JVMSerializablecontract), which is (quite obviously) not supported in GWT.That means you can safely ignore the warning; and you can also safely add a
serialVersionUIDto appease Eclipse, as it’ll be pruned by the compiler.(I believe you could also configure Eclipse so it doesn’t generate the warning)
Also, you shouldn’t initialze your
HashMapthat way (that is, create an anonymous subclass ofHashMapthat initializes itself in its initializer). You’d better use a static initializer:or use Guava’s ImmutableMap:
final static Map getType = ImmutableMap.builder()
.put(1, Types.TYPE1)
.put(1, Types.TYPE2)
…
.build();
Better yet, if your integer values map with the enum constants’ declaration order, you can simply use Enum#values() instead of map: