Java Object Clone clone(Object original)

Here you can find the source of clone(Object original)

Description

Returns a clone of the given original Object

License

Apache License

Parameter

Parameter Description
original The Object to be cloned

Exception

Parameter Description
CloneNotSupportedException if the original object is not cloneable

Return

A clone of the original object

Declaration

public static Object clone(Object original)
        throws CloneNotSupportedException 

Method Source Code

//package com.java2s;
// Licensed under the Apache License, Version 2.0 (the "License")

public class Main {
    /**// w ww.j  a v  a  2 s .c o  m
     * Returns a clone of the given original Object
     * @param original The Object to be cloned
     * @return A clone of the original object
     * @throws CloneNotSupportedException if the original object is not cloneable
     */
    public static Object clone(Object original)
            throws CloneNotSupportedException {
        if (!(original instanceof Cloneable))
            throw new CloneNotSupportedException();
        try {
            return original.getClass().getMethod("clone").invoke(original);
        } catch (Exception e) {
            throw new CloneNotSupportedException();
        }
    }
}

Related

  1. clone(E object)
  2. clone(Object a)
  3. clone(Object value)
  4. clone(String name, String type, int pos)
  5. clone(T array)
  6. clone_obj_array(Object source)