开发者

GWT LinkedHashMap.clone() issue

Faced an interesting issue recently. I've catched Cl开发者_运维技巧assCastException while executing this code:

LinkedHashMap<Tag, Boolean> tags = new LinkedHashMap<Tag, Boolean>();
...
LinkedHashMap<Tag, Boolean> tagsCopy = (LinkedHashMap<Tag, Boolean>)tags.clone();//exception on this line

In development mode it works just fine, but it fails in production somewhy. Solved it by creating a shallow copy manually. But I'm still interested in what caused such a behaviour. Any ideas?

UPD forgot to mention, I use java.util.LinkedHashMap.


clone is not supported by GWT, see issue 1843 on the GWT issue tracker. It does work in development mode as in that mode plain Java code is executed, while in production the generated JavaScript is executed, for which no working implementation of clone is generated. In issue 1843 are some suggestions for creating a GWT compatible version, but afaik those suggestions are not in the GWT implemented.


With GWT 2.4, LinkedHashMap.clone() returns a HashMap. Try using Map<...> = (Map<...>) anyOtherMap.clone(); in the general case to avoid such issues.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜