将HashMap创建为实例变量,并提供一种将其访问类API的方法:
public class DataStorage { private HashMap<String, Integer> people = new HashMap<String, Integer>(); public HashMap<String, Integer> getPeopleMap() { return people; }}public class AnotherClass { DataStorage x = new DataStorage(); private void someMethod() {HashMap<String, Integer> people = x.getPeopleMap();//work with your map here... } }
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)