public <T,E extends T>void copyPropertiesOfInheritedClass(final T src,final E dest){
  if (src == null)   throw new IllegalArgumentException("src can't be null");
  if (dest == null)   throw new IllegalArgumentException("dest can't be null");
  final Class<? extends Object> srcClz=src.getClass();
  final Class<? extends Object> destClz=dest.getClass();
  if (srcClz.isArray()) {
    if (!destClz.isArray())     throw new IllegalArgumentException("can't copy from array to non-array class " + destClz);
    final int length=Array.getLength(src);
    for (int i=0; i < length; i++) {
      final Object v=Array.get(src,i);
      Array.set(dest,i,v);
    }
    return;
  }
  final List<Field> fields=allFields(srcClz);
  final List<Field> destFields=allFields(dest.getClass());
  for (  final Field field : fields) {
    if (!Modifier.isStatic(field.getModifiers())) {
      try {
        final Object fieldObject=field.get(src);
        field.setAccessible(true);
        if (destFields.contains(field)) {
          field.set(dest,fieldObject);
        }
      }
 catch (      final IllegalArgumentException e) {
        throw new RuntimeException(e);
      }
catch (      final IllegalAccessException e) {
        throw new RuntimeException(e);
      }
    }
  }
}

public < T , E extends T > void copyPropertiesOfInheritedClass ( final T src , final E dest ) { if ( src == null ) throw new IllegalArgumentException ( "src can't be null" ) ; if ( dest == null ) throw new IllegalArgumentException ( "dest can't be null" ) ; final Class < ? extends Object > srcClz = src . getClass ( ) ; final Class < ? extends Object > destClz = dest . getClass ( ) ; if ( srcClz . isArray ( ) ) { if ( ! destClz . isArray ( ) ) throw new IllegalArgumentException ( "can't copy from array to non-array class " + destClz ) ; final int length = Array . getLength ( src ) ; for ( int i = 0 ; i < length ; i ++ ) { final Object v = Array . get ( src , i ) ; Array . set ( dest , i , v ) ; } return ; } final List < Field > fields = allFields ( srcClz ) ; final List < Field > destFields = allFields ( dest . getClass ( ) ) ; for ( final Field field : fields ) { if ( ! Modifier . isStatic ( field . getModifiers ( ) ) ) { try { final Object fieldObject = field . get ( src ) ; field . setAccessible ( true ) ; if ( destFields . contains ( field ) ) { field . set ( dest , fieldObject ) ; } } catch ( final IllegalArgumentException e ) { throw new RuntimeException ( e ) ; } catch ( final IllegalAccessException e ) { throw new RuntimeException ( e ) ; } } } }
copies all properties from src to dest . src and dest can be of different class , provided they contain same field names / types
