Colin Alworth
unread,Sep 1, 2011, 4:54:02 PM9/1/11Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
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.