Duplicate :
|
|
Relates :
|
|
Relates :
|
Name: mc57594 Date: 02/07/97 If you clone a GregorianCalendar, you get references to the same object. I you modify one, all of them get modified: import java.io.*; import java.util.*; class Test { public static void main(String[] args) { String s; GregorianCalendar d1, d2, d3; d1 = new GregorianCalendar(1997,1,16); d2 = (GregorianCalendar) d1.clone(); d3 = (GregorianCalendar) d1.clone(); d1.set(Calendar.HOUR, 9); d2.set(Calendar.HOUR, 10); d3.set(Calendar.HOUR, 11); System.out.println(d1.getTime().toString() + "\n" + d2.getTime().toString() + "\n" + d3.getTime().toString()); } } hoth% java Test Sun Feb 16 11:00:00 GMT+03:00 1997 Sun Feb 16 11:00:00 GMT+03:00 1997 Sun Feb 16 11:00:00 GMT+03:00 1997 hoth% company - Sun Microsystems , email - ###@###.### ======================================================================
|