@Test void getFromObjectError() { ClassWithStringField target = new ClassWithStringField(); calling(() -> FieldUtil.get("rubbish", target)) .shouldThrow(IllegalArgumentException.class) .withMessage(is("No such field as rubbish in class com.cadenzauk.core.reflect.util.FieldUtilTest$ClassWithStringField")); }
public static Object get(Field field, Object target) { field.setAccessible(true); try { return field.get(target); } catch (IllegalAccessException e) { throw new RuntimeException(e); } }
FieldUtil extends UtilityClass { public static Object get(Field field, Object target) { field.setAccessible(true); try { return field.get(target); } catch (IllegalAccessException e) { throw new RuntimeException(e); } } }
FieldUtil extends UtilityClass { public static Object get(Field field, Object target) { field.setAccessible(true); try { return field.get(target); } catch (IllegalAccessException e) { throw new RuntimeException(e); } }  }
FieldUtil extends UtilityClass { public static Object get(Field field, Object target) { field.setAccessible(true); try { return field.get(target); } catch (IllegalAccessException e) { throw new RuntimeException(e); } }  static void set(Field field, Object target, Object value); static Object get(Field field, Object target); static Object get(String fieldName, Object target); static Optional<Class<?>> genericTypeArgument(Field field, int index); static boolean hasAnnotation(Class<? extends Annotation> annotationClass, Field field); static Optional<A> annotation(Class<A> annotationClass, Field field); }
FieldUtil extends UtilityClass { public static Object get(Field field, Object target) { field.setAccessible(true); try { return field.get(target); } catch (IllegalAccessException e) { throw new RuntimeException(e); } }  static void set(Field field, Object target, Object value); static Object get(Field field, Object target); static Object get(String fieldName, Object target); static Optional<Class<?>> genericTypeArgument(Field field, int index); static boolean hasAnnotation(Class<? extends Annotation> annotationClass, Field field); static Optional<A> annotation(Class<A> annotationClass, Field field);  }