@Test public void shallowCopyInheritanceSimple() { G g = new G(); g.setA("aaa"); g.setB(5); g.setC(null); g.setD(new D("abcD")); g.setF(true); g.setG("ggg"); G clone = Cloner.shallowCopy(g); Assert.assertEquals(g, clone); }
@SuppressWarnings("unchecked") public static <T> T shallowCopy(T original) { Class<? extends T> clazz = (Class<? extends T>) original.getClass(); BeanClass<? extends T> beanClass = (BeanClass<? extends T>) classes.get(clazz); if (beanClass == null) { beanClass = BeanClass.buildFrom(clazz); classes.put(clazz, beanClass); } return shallowCopyHelper(original, beanClass); }
Cloner { @SuppressWarnings("unchecked") public static <T> T shallowCopy(T original) { Class<? extends T> clazz = (Class<? extends T>) original.getClass(); BeanClass<? extends T> beanClass = (BeanClass<? extends T>) classes.get(clazz); if (beanClass == null) { beanClass = BeanClass.buildFrom(clazz); classes.put(clazz, beanClass); } return shallowCopyHelper(original, beanClass); } }
Cloner { @SuppressWarnings("unchecked") public static <T> T shallowCopy(T original) { Class<? extends T> clazz = (Class<? extends T>) original.getClass(); BeanClass<? extends T> beanClass = (BeanClass<? extends T>) classes.get(clazz); if (beanClass == null) { beanClass = BeanClass.buildFrom(clazz); classes.put(clazz, beanClass); } return shallowCopyHelper(original, beanClass); }  }
Cloner { @SuppressWarnings("unchecked") public static <T> T shallowCopy(T original) { Class<? extends T> clazz = (Class<? extends T>) original.getClass(); BeanClass<? extends T> beanClass = (BeanClass<? extends T>) classes.get(clazz); if (beanClass == null) { beanClass = BeanClass.buildFrom(clazz); classes.put(clazz, beanClass); } return shallowCopyHelper(original, beanClass); }  @SuppressWarnings("unchecked") static T shallowCopy(T original); }
Cloner { @SuppressWarnings("unchecked") public static <T> T shallowCopy(T original) { Class<? extends T> clazz = (Class<? extends T>) original.getClass(); BeanClass<? extends T> beanClass = (BeanClass<? extends T>) classes.get(clazz); if (beanClass == null) { beanClass = BeanClass.buildFrom(clazz); classes.put(clazz, beanClass); } return shallowCopyHelper(original, beanClass); }  @SuppressWarnings("unchecked") static T shallowCopy(T original);  }