Class ReflectionHelper

java.lang.Object
org.faktorips.runtime.util.ReflectionHelper

public class ReflectionHelper extends Object
A helper to make dealing with Java's reflection API a little easier.
  • Method Details

    • findStaticFieldValue

      public static <R> Optional<R> findStaticFieldValue(Class<?> clazz, String fieldName)
      Finds a static field of the given name in the given class and returns its value, if such a field is present, otherwise an empty Optional.
      Type Parameters:
      R - the return value's type
      Parameters:
      clazz - a class
      fieldName - the name of a field of the class
      Returns:
      the field's value if present, otherwise an empty Optional.
    • findFieldValue

      public static <T, R> Optional<R> findFieldValue(Class<T> clazz, String fieldName, T object)
      Finds a field of the given name in the given class and returns its value from the given object, if such a field is present, otherwise an empty Optional.
      Type Parameters:
      T - the type of the class and object
      R - the return value's type
      Parameters:
      clazz - a class
      fieldName - the name of a field of the class
      object - an object of the type of the clazz; may be null for static fields
      Returns:
      the field's value if present, otherwise an empty Optional.