GWT-RPC 序列化的 ImmutableCollection 声明
我的理解是,要为 GWT RPC 序列化的 DTO 应该出于性能原因,将其字段声明为尽可能最低的实现类型。例如,人们应该偏爱 ArrayList
而不是 List
或 Collection
,这与我们通常收到的相反建议(例如,Effective Java、第 52 项)。
对于 JDK 集合,这没有问题 - 大多数时候,Map
是 HashMap
,Set
是 HashSet
并且List
是一个ArrayList
。但是,我正在使用 Guava 的 Immutable* 集合(例如 ImmutableList),我真的不知道我使用哪个实现最终会得到。我是否需要忍气吞声并让 GWT 模拟所有这些,或者有什么方法可以在这里进行损害控制?
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 HashSet
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正确的。只需使用 API 中最具体的类型即可。
用
@GwtCompatible(serializing = true)
注解的子类型可通过 GWT RPC 序列化,除非另有指定(由另一个@GwtCompatible(serializing = false)
)。您可以安全地使用Immutable*
类型作为 GWT RPC 接口。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 useImmutable*
types as GWT RPC interfaces.