public Serializable copy ( Serializable obj ) { final boolean isTraceOn = TraceComponent . isAnyTracingEnabled ( ) ; if ( isTraceOn && tc . isDebugEnabled ( ) ) Tr . debug ( tc , "copy : " + Util . identity ( obj ) ) ; // ----------------------------------------------------------------------- // Optimize copyObject by special casing null, immutable objects, // and primitive arrays. All of these can be handled much more // efficiently than performing a 'deep' copy. d154342.7 // ----------------------------------------------------------------------- if ( obj == null ) { return obj ; } Class < ? > objType = obj . getClass ( ) ; // if the object is a primitive wrapper class, then return it. if ( ( objType == String . class ) || ( objType == Integer . class ) || ( objType == Long . class ) || ( objType == Boolean . class ) || ( objType == Byte . class ) || ( objType == Character . class ) || ( objType == Float . class ) || ( objType == Double . class ) || ( objType == Short . class ) ) { // Yes, so do nothing... return obj ; } Class < ? > componentType = objType . getComponentType ( ) ; // If this is an array of primitives take a clone instead of deep copy if ( componentType != null && componentType . isPrimitive ( ) ) { if ( componentType == boolean . class ) return ( ( boolean [ ] ) obj ) . clone ( ) ; if ( componentType == byte . class ) return ( ( byte [ ] ) obj ) . clone ( ) ; if ( componentType == char . class ) return ( ( char [ ] ) obj ) . clone ( ) ; if ( componentType == short . class ) return ( ( short [ ] ) obj ) . clone ( ) ; if ( componentType == int . class ) return ( ( int [ ] ) obj ) . clone ( ) ; if ( componentType == long . class ) return ( ( long [ ] ) obj ) . clone ( ) ; if ( componentType == float . class ) return ( ( float [ ] ) obj ) . clone ( ) ; if ( componentType == double . class ) return ( ( double [ ] ) obj ) . clone ( ) ; } // End d154342.7 if ( isTraceOn && tc . isDebugEnabled ( ) ) Tr . debug ( tc , "copy : making a deep copy" ) ; return copySerializable ( obj ) ; }
Make a copy of an object by writing it out to stream and reading it back again . This will make a deep copy of the object .