Been trying to find the best way to implement a method that makes a defensive copy of a Calendar object.
eg:
public void setDate(Calendar date) {
What about the below ?
public synchronized void setDate(Calendar date) { // What to do.... Calendar anotherCalendar = Calendar.getInstance(); anotherCalendar.setTimeInMillis(date.getTimeInMillis()); }
The correct usage in code of synchronized depends on your use case.