本文共 1563 字,大约阅读时间需要 5 分钟。
java clone方法
clone() method is available in java.util package.
clone()方法在java.util包中可用。
clone() method is used to return the cloned object of this Calendar object.
clone()方法用于返回此Calendar对象的克隆对象。
clone() method is a non-static method, it is accessible with the class object and if we try to access the method with the class name then we will get an error.
clone()方法是一种非静态方法,可通过类对象访问,如果尝试使用类名称访问该方法,则会收到错误消息。
clone() method does not throw an exception at the time of cloning Calendar object.
在克隆Calendar对象时, clone()方法不会引发异常。
Syntax:
句法:
public Object clone();
Parameter(s):
参数:
It does not accept any parameter.
它不接受任何参数。
Return value:
返回值:
In both the cases, the return type of the method is Object, it returns a copy to this object.
在这两种情况下,方法的返回类型均为Object ,它将返回此对象的副本。
Example:
例:
// Java Program to demonstrate the example of// Object clone() method of Calendarimport java.util.*;public class CloneOfCalendar { public static void main(String[] args) { // Instantiating two Calendar object Calendar curr_ca = Calendar.getInstance(); Calendar clo_ca; // Display current calendar System.out.println("curr_ca: " + curr_ca.getTime()); // By using clone() method is to copy the // object to another clo_ca = (Calendar) curr_ca.clone(); // Display cloned calendar System.out.println("curr_ca.clone(): " + clo_ca.getTime()); }}
Output
输出量
curr_ca: Thu Jan 23 11:42:29 GMT 2020curr_ca.clone(): Thu Jan 23 11:42:29 GMT 2020
翻译自:
java clone方法
转载地址:http://khxzd.baihongyu.com/