Class DefaultMemberInvoker

java.lang.Object
io.fluxcapacitor.common.reflection.DefaultMemberInvoker
All Implemented Interfaces:
MemberInvoker

public class DefaultMemberInvoker extends Object implements MemberInvoker
Default implementation of MemberInvoker using high-performance method handle-based invocation.

This implementation attempts to convert reflective member access into a compiled lambda expression via LambdaMetafactory and MethodHandle, avoiding the overhead of standard Java reflection.

Key Features

  • Caches compiled lambda invokers for reuse
  • Falls back to reflection if lambda creation is not possible
  • Supports methods, constructors, and fields (read/write)
  • Supports up to 10 parameters per method (beyond which it falls back)

Usage example:


 Method m = MyClass.class.getDeclaredMethod("doSomething", String.class);
 MemberInvoker invoker = DefaultMemberInvoker.asInvoker(m);
 Object result = invoker.invoke(myInstance, "value");
 
  • Method Details

    • asInvoker

      public static MemberInvoker asInvoker(Member member)
    • asInvoker

      public static MemberInvoker asInvoker(Member member, boolean forceAccess)
    • invoke

      public Object invoke(Object target, int parameterCount, IntFunction<?> paramProvider)
      Description copied from interface: MemberInvoker
      Invokes the member with the provided number of parameters using a parameter provider.
      Specified by:
      invoke in interface MemberInvoker
      Parameters:
      target - the target object
      parameterCount - the number of parameters to use
      paramProvider - a function to supply parameters by index
      Returns:
      the invocation result