| Other |
|---|
| 5.0 b28Fixed |
|
Relates :
|
|
|
Relates :
|
|
|
Relates :
|
|
|
Relates :
|
|
|
Relates :
|
The following program shows that Calendar.equals changes the observable state of the calendar. The output I got is:
Date with equals: Tue May 30 20:25:08 PDT 2000
Date without equals: Sun Apr 30 20:25:08 PDT 2000
Calling a.equals(b) should never, ever have any observable effect on a or b.
import java.util.Calendar;
public class CalEquals {
public static void main(String[] args) {
Calendar cal1 = makeCalendar();
Calendar cal2 = makeCalendar();
Calendar cal3 = makeCalendar();
cal1.equals(cal2);
cal1.set(Calendar.DAY_OF_MONTH, 30);
cal3.set(Calendar.DAY_OF_MONTH, 30);
System.out.println("Date with equals: " + cal1.getTime());
System.out.println("Date without equals: " + cal3.getTime());
}
private static Calendar makeCalendar() {
Calendar cal = Calendar.getInstance();
cal.set(Calendar.MONTH, Calendar.APRIL);
cal.set(Calendar.DAY_OF_MONTH, 31);
return cal;
}
}
The Date class has the same problem since JDK1.0.
###@###.### 2002-08-05
|