why we must do Defensive Copying in order to achieve Immutable class? Look at this code:
public final class EmailMessage {
private final String from;
private final String to;
private final String message;
private final Date date;
public EmailMessage( String from, String to, String msg, Date date )
{
this.to = to;
this.from = from;
this.message = msg;
this.date = new Date(date.getTime());// instead of date;
}
public String getFrom()
{
return( from );
}
public Date getDate() {
return( new Date( date.getTime() ); // instead of Date
}
}
Why it won't be Immutable if we didn't do Defensive Copying?