I have developed a below code based on the concept of immutability , as we know in java string class is immutable so I also developed the below class as immutable , please advise me is it correct as per the immutablility..
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());
}
}
This is correct, as there is no way to modify the object