Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

setting value of map from another class

 
kamesh aru
Ranch Hand
Posts: 150
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have a class containg map with values set.
i want to change this values from another class.

here is the class with map
public class Status {


private static Map map = new HashMap();
Status(){
map.put("abc","true");
map.put("cfv","true");
map.put("vgf","true");
map.put("vfg","true");


}






/**
* @return
*/
public static Map getMap() {
return map;
}

/**
* @param map
*/
public static void setMap(Map map) {
Status.map = map;
}

}
i need to set the value of this map in other class can any one help me out
thanks in advance
 
Rick O'Shay
Ranch Hand
Posts: 531
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What do you mean change the value of this map from another class?

You have a getMap method so you can use that. Since it is static you setMap should synchronize:

public void setMap(Map map) { Status.map = Collections.synchronizedMap(map); }

You must make sure you only use the reference returned by getMap to manipulate the map.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic