public static < T > T fill ( T destination , Object source ) { if ( destination != source ) { Class < ? > stype = source . getClass ( ) ; for ( Field field : destination . getClass ( ) . getFields ( ) ) { try { Object value = field . get ( destination ) ; if ( value == null ) { field . set ( destination , stype . getField ( field . getName ( ) ) . get ( source ) ) ; } } catch ( Exception x ) { } } } return destination ; }
Fills empty identically named public fields with values from another object .