3131
3232import static io .microsphere .invoke .MethodHandleUtils .findVirtual ;
3333import static io .microsphere .reflect .MethodUtils .findFunctionalInterfaceMethod ;
34+ import static io .microsphere .util .ArrayUtils .combine ;
3435import static java .lang .invoke .LambdaMetafactory .metafactory ;
3536import static java .lang .invoke .MethodHandles .lookup ;
3637import static java .lang .invoke .MethodType .methodType ;
@@ -49,30 +50,28 @@ public abstract class LambdaUtils implements Utils {
4950 /**
5051 * Creates a {@link Function} lambda instance for the specified target class, and method.
5152 *
52- * @param targetClass the target class containing the method to be invoked
53- * @param methodName the name of the method to be invoked
54- * @param parameterTypes the parameter types of the method to be invoked
55- * @param <T> the type of the function input
56- * @param <R> the return type of the function
53+ * @param targetClass the target class containing the method to be invoked
54+ * @param methodName the name of the method to be invoked
55+ * @param <T> the type of the function input
56+ * @param <R> the return type of the function
5757 * @return a {@link Function} lambda instance
5858 * @throws Throwable if an error occurs during lambda creation
5959 */
60- public static <T , R > Function <T , R > function (Class <T > targetClass , String methodName , Class <?>... parameterTypes ) throws Throwable {
61- return lambda (Function .class , targetClass , methodName , parameterTypes );
60+ public static <T , R > Function <T , R > function (Class <T > functionInputType , Class <T > targetClass , String methodName ) throws Throwable {
61+ return lambda (Function .class , functionInputType , targetClass , methodName );
6262 }
6363
6464 /**
6565 * Creates a {@link Consumer} lambda instance for the specified target class, and method.
6666 *
67- * @param targetClass the target class containing the method to be invoked
68- * @param methodName the name of the method to be invoked
69- * @param parameterTypes the parameter types of the method to be invoked
70- * @param <T> the type of the consumer input
67+ * @param targetClass the target class containing the method to be invoked
68+ * @param methodName the name of the method to be invoked
69+ * @param <T> the type of the consumer input
7170 * @return a {@link Consumer} lambda instance
7271 * @throws Throwable if an error occurs during lambda creation
7372 */
74- public static <T > Consumer <T > consumer (Class <T > targetClass , String methodName , Class <?>... parameterTypes ) throws Throwable {
75- return lambda (Consumer .class , targetClass , methodName , parameterTypes );
73+ public static <T > Consumer <T > consumer (Class <T > functionInputType , Class <T > targetClass , String methodName ) throws Throwable {
74+ return lambda (Consumer .class , functionInputType , targetClass , methodName );
7675 }
7776
7877 /**
@@ -81,12 +80,13 @@ public static <T> Consumer<T> consumer(Class<T> targetClass, String methodName,
8180 * @param functionalInterface the functional interface class
8281 * @param targetClass the target class containing the method to be invoked
8382 * @param methodName the name of the method to be invoked
84- * @param parameterTypes the parameter types of the method to be invoked
83+ * @param parameterTypes the types of the method parameters
8584 * @param <F> the type of the functional interface
8685 * @return a lambda instance implementing the specified functional interface
8786 * @throws Throwable if an error occurs during lambda creation
8887 */
89- public static <F > F lambda (Class <F > functionalInterface , Class <?> targetClass , String methodName , Class <?>... parameterTypes ) throws Throwable {
88+ public static <F > F lambda (Class <F > functionalInterface , Class <?> functionInputType ,
89+ Class <?> targetClass , String methodName , Class <?>... parameterTypes ) throws Throwable {
9090 // 1. Set up the target method lookup context
9191 Lookup lookup = lookup ();
9292
@@ -102,7 +102,8 @@ public static <F> F lambda(Class<F> functionalInterface, Class<?> targetClass, S
102102 MethodType samMethodType = methodType (functionalInterfaceReturnType , functionalInterfaceMethodParameterTypes );
103103
104104 // The type signature of the functional interface's abstract method (instantiated type)
105- MethodType instantiatedMethodType = methodType (functionalInterfaceReturnType , targetClass );
105+ Class <?>[] instantiatedMethodParameterTypes = combine (functionInputType , parameterTypes );
106+ MethodType instantiatedMethodType = methodType (functionalInterfaceReturnType , instantiatedMethodParameterTypes );
106107
107108 // 4. Invoke LambdaMetafactory to spin the runtime lambda class
108109 CallSite callSite = metafactory (
0 commit comments