Is it still preferable to have HashMap<String, Panel> over Map<String, Panel> in GWT client side code?

53 views
Skip to first unread message

Blackberet

unread,
Sep 1, 2011, 12:00:56 PM9/1/11
to google-we...@googlegroups.com
thanks

Paul Robinson

unread,
Sep 1, 2011, 12:17:17 PM9/1/11
to google-we...@googlegroups.com
For anything going over the wire via RPC, yes.

For anything that stays within the client, it doesn't matter.

Blackberet

unread,
Sep 1, 2011, 4:43:30 PM9/1/11
to google-we...@googlegroups.com
But does the GWT compiler generate extra code to convert from Map to HashMap?

Colin Alworth

unread,
Sep 1, 2011, 4:54:02 PM9/1/11
to google-we...@googlegroups.com
In general the compiler will select the most specific type it can - if you write
Map<String, Panel> map = new HashMap<String, Panel>();
it will change that to
HashMap<String, Panel> map = new HashMap<String, Panel>();
as it is clear that the object can only be a HashMap at that location. In other cases it may not be able to make that promotion, but there is no 'extra code' to convert from one to the other, as HashMap implements Map, and Map's methods may then be invoked on HashMap.

The one slight cost that could exist would be when the compiler attempts to turn instance methods into static methods, as to avoid the small cost for dynamic dispatch. It is worth noting that making this change throughout your codebase is unlikely to cause a significant size difference, as Widget has a HandlerManager, and HandlerManager has an EventBus, usually of type SimpleEventBus, which has a Map in it, where the actual value is a HashMap. Thus both classes are necessary (assuming you use any Widget or Widget subclass in your app), as is the ability to refer to a HashMap as a Map.
Reply all
Reply to author
Forward
0 new messages