0
可能重复:类
Considering object encapsulation, should getters return an immutable property?封装在Java中
是否封装任务不变性?
Class Employee{
private Date hireDate;
public Date getHireDate(){
return hireDate;
}
}
在某些客户端方法:
Employee emp = new Employee();
Date temp = emp.getHireDate();
temp.setTime(...);//The Hiredate of the employee would be corrupted...