Class ReflectionUtil

java.lang.Object
info.u_team.u_team_core.util.ReflectionUtil

public class ReflectionUtil extends Object
Utility methods for reflection stuff
  • Constructor Details

    • ReflectionUtil

      public ReflectionUtil()
  • Method Details

    • findField

      public static Field findField(Class<?> clazz, String field)
      Method to find a field in a give class. The name will be mapped to the right mappings. Will return the field with widened access.
      Parameters:
      clazz - Class of the field
      field - The name of the field
      Returns:
      The field
    • setValue

      public static <I, V> void setValue(Field field, I instance, V value)
      Sets the value of a field. Catches exceptions and throws a runtime exception.
      Parameters:
      field - The field
      instance - The object instance. Null for static fields
      value - The value
    • getValue

      public static <I, V> V getValue(Field field, I instance)
      Gets the value of a field. Catches exceptions and throws a runtime exception.
      Parameters:
      field - The field
      instance - The object instance. Null for static fields
      Returns:
      The value
    • copyValue

      public static <O, N> void copyValue(Field field, O oldInstance, N newInstance)
      Utility method to copy a field value from an old oject instance to a new instance. Catches exceptions and throws a runtime exception.
      Parameters:
      field - The field
      oldInstance - Old object
      newInstance - New object