Class ReflectionCloning

java.lang.Object
io.github.connellite.cloner.ReflectionCloning

public class ReflectionCloning extends Object
Deep / shallow cloning via reflection. Instances are created with the no-arg constructor (see ReflectionUtil.getInstance(Class)); classes without one cannot be cloned this way. Common immutable JDK types (including String) are not traversed: the same instance is reused.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static <T> T
    clone(T original)
    Deep clone: copies the object graph; shared references become shared in the clone unless broken by cycle handling.
    static <T> T
    shallowClone(T original)
    Shallow clone: new outer instance; field values are the same references as in the original.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • ReflectionCloning

      public ReflectionCloning()
  • Method Details

    • clone

      public static <T> T clone(T original)
      Deep clone: copies the object graph; shared references become shared in the clone unless broken by cycle handling.
    • shallowClone

      public static <T> T shallowClone(T original)
      Shallow clone: new outer instance; field values are the same references as in the original.