Class ReflectionUtils

java.lang.Object
com.jbstrap.core.utils.ReflectionUtils

public final class ReflectionUtils extends Object
Since:
4.0
Author:
JBStrap
  • Method Details

    • setField

      public static void setField(Object obj, String fieldName, Object data)
      Parameters:
      obj - The object where the value will be set
      fieldName - The name of the field, that will have its value set
      data - The value to be set
      Throws:
      IllegalStateException - If the field value couldn't be set
      NullPointerException - If the object or field name was defined as null
    • getField

      public static <T> T getField(Object obj, String fieldName)
      Type Parameters:
      T - The type of the returned value
      Parameters:
      obj - The source object
      fieldName - The name of the field
      Returns:
      The field value
      Throws:
      NullPointerException - If the specified object value is null
      IllegalStateException - If the field value was not found
    • invoke

      public static Object invoke(Object obj, String methodName, Object... params) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException
      Parameters:
      obj - The object where the method will be used
      methodName - The name of the method
      params - The method parameters
      Returns:
      The methods return value
      Throws:
      NoSuchMethodException - If the specified method was not found
      IllegalAccessException - If the invoking code has no access rights to the specified method
      InvocationTargetException - If the target couldn't be found
    • calledFromMethod

      public static boolean calledFromMethod(String methodName)
      Parameters:
      methodName - The name of the method
      Returns:
      true, if the method is in the chain, otherwise false