ImmutableCollection declarations for GWT-RPC serialization
My understanding is that DTOs to be serialized for GWT RPC ought to declare their fields of the lowest possible implementation type for performance reasons. For example, one should favor ArrayList
over List
or Collection
, in defiance of the advice we normally receive to the contrary (e.g., Effective Java, Item 52).
With the JDK collections, this is no problem—most of the time, a Map
is a HashMap
, a Set
is a H开发者_运维百科ashSet
and a List
is an ArrayList
. However, I am using Guava's Immutable* collections (e.g., ImmutableList), where I really don't know which implementation I'll end up getting. Do I need to just suck it up and let GWT emulate all of them, or is there any way to do damage control here?
Right. Just use the most specific type that is part of the API.
Subtypes that are annotated with @GwtCompatible(serializable = true)
are serializable over GWT RPC unless otherwise specified (by another @GwtCompatible(serializable = false)
). You can safely use Immutable*
types as GWT RPC interfaces.
精彩评论