0
我已經開發了一個基於不變性概念的下面的代碼,正如我們在java中所知的那樣,string類是不可變的,所以我也開發了下面的類作爲不可變的,請告訴我它是否正確無誤。關於不可變的類
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());
}
}
@ Luchian..yeah哥們使其最終給予更多的屏蔽 – dghtr
還有引用當Java內存模型由'final'領域具有一定的保障跨多個線程的實例。 – Grundlefleck