Class Reflex

java.lang.Object
valorless.rarespawns.utils.Reflex

public class Reflex extends Object
Lightweight reflection helpers for accessing private members and invoking methods.

Notes:

  • getMethod and setFieldValue operate on declared members of the given class only (no superclass traversal).
  • Members are set accessible=true before use.
  • Errors are logged via stack traces; null is returned or the call is no-op on failure.

  • Constructor Details

    • Reflex

      public Reflex()
  • Method Details

    • getMethod

      public static Method getMethod(Class<?> clazz, String name, Class<?>... parameterTypes)
      Returns a declared Method from the specified class and makes it accessible.

      This does not search superclasses; use clazz.getSuperclass() manually if needed.

      Parameters:
      clazz - the class declaring the method
      name - the method name
      parameterTypes - the formal parameter types in declaration order
      Returns:
      the accessible Method, or null if not found
    • invokeMethod

      public static void invokeMethod(Method method, Object instance, Object... args)
      Invokes a Method on the given instance with the provided arguments.

      For static methods, pass null as the instance. Any return value is ignored. Exceptions are caught and printed.

      Parameters:
      method - the method to invoke (should already be accessible)
      instance - the target object instance, or null for static methods
      args - the arguments to pass to the invocation
    • setFieldValue

      public static void setFieldValue(Object instance, String fieldName, Object value)
      Sets the value of a declared field on an instance and makes it accessible.

      This does not search superclasses; only the instance's concrete class is used. Exceptions are caught and printed.

      Parameters:
      instance - the object whose field should be updated
      fieldName - the declared field name on the instance's class
      value - the value to assign to the field