「java」Java.lang.Object.clone()メソッドを使うサンプル
説明
このオブジェクトのコピーを作成して返します。
javaコード
package com.arkgame.study; import java.util.GregorianCalendar; public class ObjectTestDemo { public static void main(String[] args) { //create a gregorian calendar, which is an object GregorianCalendar gcA = new GregorianCalendar(); //clone object gcA into object gcB GregorianCalendar gcB = (GregorianCalendar) gcA.clone(); //print both System.out.println("result1: " + gcA.getTime() + "TimeZone: " + gcA.getTimeZone()); System.out.println("result2: " + gcB.getTime() + "TimeZone: " + gcB.getTimeZone()); } }
結果
result1: Sun Nov 01 15:48:19 JST 2020TimeZone: sun.util.calendar.ZoneInfo[id="Asia/Tokyo",offset=32400000,dstSavings=0,useDaylight=false,transitions=10,lastRule=null]
result2: Sun Nov 01 15:48:19 JST 2020TimeZone: sun.util.calendar.ZoneInfo[id="Asia/Tokyo",offset=32400000,dstSavings=0,useDaylight=false,transitions=10,lastRule=null]