Interface InvokeFactory<F,T>

Type Parameters:
F - type of functional interface implemented
T - type of target value
All Known Implementing Classes:
SimpleInvokeFactory

public interface InvokeFactory<F,T>
Factory for implementing functional interfaces at runtime.
  • Method Details

    • using

      InvokeFactory<F,T> using(@NonNull @NonNull LookupFactory lookupFactory)
      Specifies the lookup factory to be used for creation of lookup
      Parameters:
      lookupFactory - lookup factory to be used for creation of lookup
      Returns:
      this invoke factory
    • implementing

      InvokeFactory<F,T> implementing(@NonNull @NonNull MethodType functionalInterface, @NonNull @NonNull String functionalMethodName, @NonNull @NonNull MethodType functionalMethodSignature)
      Specifies the functional interface implemented.
      Parameters:
      functionalInterface - type of the implemented functional interface (always has return type and no parameters)
      functionalMethodName - name of the implemented functional method
      functionalMethodSignature - signature of the implemented functional method
      Returns:
      this invoke factory
      Throws:
      IllegalArgumentException - if functionalInterface has parameters
      API note
      even if the generated functional interface is going to be bound instance, functionalInterface should have no parameters
    • implementing

      default InvokeFactory<F,T> implementing(@NonNull @NonNull Class<? super F> functionalInterface, @NonNull @NonNull String functionalMethodName, @NonNull @NonNull Class<?> functionalMethodReturnType, @NonNull @NonNull Class<?>... functionalMethodParameterTypes)
      Specifies the functional interface implemented.
      Parameters:
      functionalInterface - type of the implemented functional interface
      functionalMethodName - name of the implemented functional method
      functionalMethodReturnType - return type of the functional method
      functionalMethodParameterTypes - parameter types of the functional method
      Returns:
      this invoke factory
    • implementing

      default InvokeFactory<F,T> implementing(@NonNull @NonNull Class<? super F> functionalInterface)
      Specifies the functional interface implemented.
      Parameters:
      functionalInterface - type of the implemented functional interface which will be searched for a single abstract method
      Returns:
      this invoke factory
      Throws:
      IllegalArgumentException - if the given class contains not 1 abstract (aka functional) method
    • via

      InvokeFactory<F,T> via(@NonNull @NonNull Class<? extends T> targetClass, @NonNull @NonNull Function<MethodHandles.Lookup,MethodHandle> methodHandleCreator)
      Specifies the target class with function which will be used to create a related MethodHandle.
      Parameters:
      targetClass - class to whom the method-handle relates
      methodHandleCreator - function creating a MethodHandle using the given lookup
      Returns:
      this invoke factory
      See Also:
    • via

      default InvokeFactory<F,T> via(@NonNull @NonNull Method method)
      Specifies the method to be invoked by the call to functional interface's method.
      Parameters:
      method - method to call
      Returns:
      this invoke factory
      See Also:
    • via

      default InvokeFactory<F,T> via(@NonNull @NonNull Constructor<? extends T> constructor)
      Specifies the constructor to be invoked by the call to functional interface's method.
      Parameters:
      constructor - constructor to call
      Returns:
      this invoke factory
      See Also:
    • boundTo

      InvokeFactory<F,T> boundTo(@Nullable T target)
      Binds the method call to the specified instance.
      Parameters:
      target - instance of the target class to use for non-static invocation or null to unbound (make the call static)
      Returns:
      this invoke factory
    • unbound

      InvokeFactory<F,T> unbound()
      Unbinds the method call from instance (making it static).
      Returns:
      this invoke factory
    • create

      F create() throws Throwable
      Creates the implementation of the functional interface.
      Returns:
      implemented functional interface
      Throws:
      IllegalStateException - if any of the required factory properties has not been set
      Throwable - if an exception occurs while creating an implementation of the functional interface
    • createUnsafely

      default F createUnsafely()
      Creates the implementation of the functional interface not declaring throws. This is actually an alias of create(). May actually throw an exception (with the same logic as create()).
      Returns:
      implemented functional interface
      Throws:
      IllegalStateException - if any of the required factory properties has not been set