Class Reflections

java.lang.Object
io.github.cjstehno.testthings.util.Reflections

public final class Reflections extends Object
Some utility methods for working with reflection. These are mostly meant for internal use.
  • Constructor Details

    • Reflections

      public Reflections()
  • Method Details

    • extractValue

      public static <R> R extractValue(Object classOrInstance, Field field, Class<? extends R> valueType)
      Extracts the value from the field of the specified instance or class with the given type. Any exception is wrapped in a RuntimeException.
      Type Parameters:
      R - the value type of the field
      Parameters:
      classOrInstance - the class or instance where the field is defined
      field - the field
      valueType - the value type of the field
      Returns:
      the extracted field value
    • invokeMethod

      public static void invokeMethod(Object classOrInstance, Method method)
      Invokes a non-returning method on the specified class or instance. Any exception is wrapped in a RuntimeException.
      Parameters:
      classOrInstance - the class or instance where the method is defined
      method - the method