I have this GWT code below which have some slight problem:
It’s either the login and aboutme property is set or just the contacts is set which ever comes first in the line. Could this be that the contacts property is set before the for-loop is finished, resulting in contacts being assigned a null?
public void copyFrom(User user) {
Map<String,String> map = new HashMap<String,String>();
for (Contact contact : user.getContacts()) {
map.put(contact.getType(), contact.getValue());
}
super.set("lastlogin", user.getLastLogin());
super.set("aboutme", user.getAboutMe());
super.set("contacts", map);
}
Do I need to use a “faster” Map?
Neither a for loop, nor adding values to a
Mapare asynchronous operations, so that entire loop executes prior to the calls tosuper.set(...). Themap, in this case, cannot benull, since you instantiate it at the moment of declaration. It could end up being unpopulated (for instance, if there were no elements inuser.getContacts()), but not null.Your problem lies in the implementation of
set(...)by whateversuperis in this case.