关于java的引用类型

假设我有几个成员变量,是下面这个样子:

List<User> userList;
Map<String,User> userMap;
Map<Integer,List<User>> userAgeMap;

然后我在set方法中为其赋值,如下:

public void setUserList(List<User> users){
	this.userList=users;
	this.userMap=users.stream().collect(Collectors.toMap(User::getName,Function.identity());
	this.userAgeMap=user.stream().collect(Collectors.groupingBy(User::getAge));
}

然后我有下面一段代码:

public void main(String[] args){
	User user=userList.get("Bob");
	user.setAddress("这是一个新的地址");
	
	//打印list,map,maplist
	System.out.println(userList);
	System.out.println(userMap);
	System.out.println(userAgeMap);

}

打印出来是何情景呢?
其实我想问的是,此时list,map和maplist中的Bob对象,是不是同一个对象?

答案是,是同一个对象。

你可能感兴趣的:(java,开发语言)