Record Class ReflectionExecutor

java.lang.Object
java.lang.Record
pro.verron.officestamper.core.ReflectionExecutor
Record Components:
object - the object on which to invoke the method.
method - the method to invoke.
All Implemented Interfaces:
org.springframework.expression.MethodExecutor

public record ReflectionExecutor(Object object, Method method) extends Record implements org.springframework.expression.MethodExecutor
A record encapsulating an object and a method, and providing functionality to execute the method on the given object using reflection. This record implements the MethodExecutor interface and serves as a mechanism to invoke methods dynamically.
  • Constructor Summary

    Constructors
    Constructor
    Description
    ReflectionExecutor(Object object, Method method)
    Creates an instance of a ReflectionExecutor record class.
  • Method Summary

    Modifier and Type
    Method
    Description
    final boolean
    Indicates whether some other object is "equal to" this one.
    org.springframework.expression.TypedValue
    execute(org.springframework.expression.EvaluationContext context, Object target, @Nullable Object... arguments)
    Executes the provided method on the given object using the specified arguments.
    final int
    Returns a hash code value for this object.
    Returns the value of the method record component.
    Returns the value of the object record component.
    final String
    Returns a string representation of this record class.

    Methods inherited from class Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • ReflectionExecutor

      public ReflectionExecutor(Object object, Method method)
      Creates an instance of a ReflectionExecutor record class.
      Parameters:
      object - the value for the object record component
      method - the value for the method record component
  • Method Details

    • execute

      public org.springframework.expression.TypedValue execute(org.springframework.expression.EvaluationContext context, Object target, @Nullable Object... arguments) throws org.springframework.expression.AccessException
      Executes the provided method on the given object using the specified arguments. This method utilizes reflection to invoke the target method dynamically.
      Specified by:
      execute in interface org.springframework.expression.MethodExecutor
      Parameters:
      context - the evaluation context in which this execution occurs.
      target - the target object on which the method should be invoked.
      arguments - the arguments to be passed to the method during invocation.
      Returns:
      a TypedValue wrapping the result of the invoked method.
      Throws:
      org.springframework.expression.AccessException - if the method cannot be accessed or invoked, or if an error occurs during invocation.
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • object

      public Object object()
      Returns the value of the object record component.
      Returns:
      the value of the object record component
    • method

      public Method method()
      Returns the value of the method record component.
      Returns:
      the value of the method record component