3 ms·
Or possibly better: private Date date; public Date getDate() { return new Date(date.getTime()); }
by taftster 14y ago
Or possibly better:
private Date date;
public Date getDate() { return new Date(date.getTime()); }
- rdwallis 14y agoYour code solves the external side effects problem but using the primitive also allows the time to be finalized eg: private final long creationTime = System.currentTimeMillis(); so it still has advantages over making the field a Date object.