@ SuppressWarnings ( "unchecked" ) public static < R > R getField ( final Object object , final String fieldName ) { try { return traverseClassHierarchy ( object . getClass ( ) , NoSuchFieldException . class , new InsideTraversal < R > ( ) { @ Override public R run ( Class < ? > traversalClass ) throws Exception { Field field = traversalClass . getDeclaredField ( fieldName ) ; field . setAccessible ( true ) ; return ( R ) field . get ( object ) ; } } ) ; } catch ( Exception e ) { throw new RuntimeException ( e ) ; } }
Reflectively get the value of a field .