I have a simple bean like this:
class Account {
private String username;
private String password;
private Map<String, String> extras;
String getUsername() {
return username;
}
void setUsername(String username) {
this.username = username;
}
String getPassword() {
return password;
}
void setPassword(String password) {
this.password = password;
}
Map<String, String> getExtras() {
return extras;
}
void setExtras(Map<String,String> attr) {
this.extras=attr;
}
}
now I'm going to set extra by:
Account tmpAccount=new Account();
tmpAccount.setExtras(new HashMap<String, String>().put("x","y"));
but I got this error:
setExtras(Map<String,String> in Account cannot be applied to Object.
Why?
new HashMap<String, String>().put("x","y")doesn't bring you the same HashMap, the methodput("x","y")will rather bring you the last object mapped as "x"private Map<String, String> extras = Collections.emptyMap();and set your Strings to ""