我已经基于不可变的概念开发了一个下面的代码,正如我们在 java 字符串类中所知道的那样是不可变的,所以我也开发了下面的类作为不可变的,请告诉我它是否正确根据不可变..
public final class BrokenPerson
{
private String firstName;
private String lastName;
private Date dob;
public BrokenPerson( String firstName, String lastName, Date adob)
{
this.firstName = firstName;
this.lastName = lastName;
this.dob = new Date(adob.getTime());
}
public String getFirstName()
{
return this.firstName;
}
public String getLastName()
{
return this.lastName;
}
public Date getDOB()
{
return new Date(dob.getTime());
}
}