Java Object Clone clone(Object value)

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

Description

clone

License

Open Source License

Declaration

static Object clone(Object value) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    static Object clone(Object value) {// throws
        // CloneNotSupportedException {
        Object rval = null;//w w w. j a va  2s .c  om
        if (value instanceof Cloneable) {
            try {
                rval = value.getClass().getMethod("clone").invoke(value);
            } catch (final Exception e) {
                rval = e;
            }
        }
        if (rval == null || rval instanceof Exception) {
            // the object wasn't cloneable, or an error occured
            if (value == null || value instanceof String || value instanceof Number || value instanceof Boolean) {
                // strings numbers and booleans are immutable
                rval = value;
            } else {
                // TODO: making this throw runtime exception so it doesn't have
                // to be caught
                // because simply it should never fail in the case of JSON-LD
                // and means that
                // the input JSON-LD is invalid
                throw new RuntimeException(new CloneNotSupportedException(
                        (rval instanceof Exception ? ((Exception) rval).getMessage() : "")));
            }
        }
        return rval;
    }
}

Related

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