在课程经理中,我有几个使用HashMap的方法,因此添加了删除等。
课程经理
HashMap<String, User> UserMap = new HashMap<String, User>();
//methods here to manage the User values.
类接口
我想获取此hashmap的实例。 有人可以帮我弄这个吗 ?
答案 0 :(得分:0)
首先,请不要使用Interface
作为类名。
public class Manager {
private HashMap<String, User> UserMap = new HashMap<String, User>();
public HashMap<String, User> getUserMap() {
return UserMap;
}
public void setUserMap(HashMap<String, User> UserMap) {
this.UserMap = UserMap;
}
// other operations
}
public class Interface{
private HashMap<String, User> UserMap =null;
public void setUserMap(HashMap<String, User> UserMap) {
this.UserMap = UserMap;
}
}
public class AnotherClass{
public static void main(String[] args) {
AnotherClass anotherClassObj= new AnotherClass();
anotherClassObj.go();
}
public void go(){
Manager obj1=new Manager();
///obj1 operations
Interface obj2=new Interface();
obj2.setUserMap(obj1.getUserMap());
//obj2 operations
}
}