shadowapi/src/main/java/org/robolectric/util/ReflectionHelpers.java
@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);
    }
  }
@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);
    }
  }
@ 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.

@param object Target object.
@param fieldName The field name.
@param <R> The return type.
@return Value of the field on the object.
Reflectively get the value of a field .