【发布时间】:2015-02-06 16:53:06
【问题描述】:
在我的 GWT 客户端代码中,我有一个类如下
public class SomeClass {
private Map<Integer, Serializable> mId2ContentMap;
private Map<Integer, Timestamp> mId2Timestamp;
public SomeClass() {
mId2ContentMap = Collections.synchronizedMap(new HashMap<Integer, Serializable>());
mId2Timestamp = Collections.synchronizedMap(new HashMap<Integer, Timestamp>());
}
}
当我尝试运行我的 GWT Web 应用程序时,我收到两个错误提示
The method synchronizedMap(HashMap<Integer,Serializable>) is undefined for the type Collections
The method synchronizedMap(HashMap<Integer,Timestamp>) is undefined for the type Collections
google了一会儿,我只发现one post与我遇到的错误远程相关。那篇文章提到 GWT 不支持反射调用。但我不认为Collections.synchronizedMap() 是一个反思电话。如果我在这里错了,请纠正我。
有什么建议吗?
【问题讨论】:
-
为什么要在 GWT 客户端代码中使用同步集合? GWT 应用程序转换为 Javascript 并且 JavaScript 不支持多线程。否则 GWT 限制了 JDK compatibility
-
@xRomZak 谢谢,您的评论和参考帮助。
标签: java gwt collections synchronization