Interface InvokeFactory<F,T>
- Type Parameters:
F- type of functional interface implementedT- type of target value
- All Known Implementing Classes:
SimpleInvokeFactory
public interface InvokeFactory<F,T>
Factory for implementing functional interfaces at runtime.
-
Method Summary
Modifier and TypeMethodDescriptionBinds the method call to the specified instance.create()Creates the implementation of the functional interface.default FCreates the implementation of the functional interface not declaringthrows.default InvokeFactory<F,T> implementing(@NonNull Class<? super F> functionalInterface) Specifies the functional interface implemented.default InvokeFactory<F,T> implementing(@NonNull Class<? super F> functionalInterface, @NonNull String functionalMethodName, @NonNull Class<?> functionalMethodReturnType, @NonNull Class<?>... functionalMethodParameterTypes) Specifies the functional interface implemented.implementing(@NonNull MethodType functionalInterface, @NonNull String functionalMethodName, @NonNull MethodType functionalMethodSignature) Specifies the functional interface implemented.unbound()Unbinds the method call from instance (making it static).using(@NonNull LookupFactory lookupFactory) Specifies the lookup factory to be used for creation of lookupvia(@NonNull Class<? extends T> targetClass, @NonNull Function<MethodHandles.Lookup, MethodHandle> methodHandleCreator) Specifies the target class with function which will be used to create a relatedMethodHandle.default InvokeFactory<F,T> via(@NonNull Constructor<? extends T> constructor) Specifies the constructor to be invoked by the call to functional interface's method.default InvokeFactory<F,T> Specifies the method to be invoked by the call to functional interface's method.
-
Method Details
-
using
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 methodfunctionalMethodSignature- signature of the implemented functional method- Returns:
- this invoke factory
- Throws:
IllegalArgumentException- iffunctionalInterfacehas parameters- API note
- even if the generated functional interface is going to be bound instance,
functionalInterfaceshould 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 interfacefunctionalMethodName- name of the implemented functional methodfunctionalMethodReturnType- return type of the functional methodfunctionalMethodParameterTypes- parameter types of the functional method- Returns:
- this invoke factory
-
implementing
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 relatedMethodHandle.- Parameters:
targetClass- class to whom the method-handle relatesmethodHandleCreator- function creating aMethodHandleusing the given lookup- Returns:
- this invoke factory
- See Also:
-
via
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
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
Binds the method call to the specified instance.- Parameters:
target- instance of the target class to use for non-static invocation ornullto 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
Creates the implementation of the functional interface.- Returns:
- implemented functional interface
- Throws:
IllegalStateException- if any of the required factory properties has not been setThrowable- if an exception occurs while creating an implementation of the functional interface
-
createUnsafely
Creates the implementation of the functional interface not declaringthrows. This is actually an alias ofcreate(). May actually throw an exception (with the same logic ascreate()).- Returns:
- implemented functional interface
- Throws:
IllegalStateException- if any of the required factory properties has not been set
-