Class type in lambda inside collectors-map-java8

Viewed 682

I have a method signature for getting setter method using reflection based on a given getter method of type Method. Signature of the method is below:

Method getSetter(final Method getterMethod, final Class classType)

Now from the method for a class I want a map of getter method to associated setter method. My code is below:

final Method[] methods = classType.getMethods();
        Stream.of(methods)
                .filter(ReflectionUtils::isGetter)
                .collect(Collectors.toMap(Function.identity(), (method) -> getSetter(method, classType)));

I am getting compilation error at getSetter(method, classType) It says Wrong first type argument Found:<lambda parameter>, required: java.lang.reflect.Method

I also tried specifying the type for the lambda parameter. See below

Stream.of(methods)
                .filter(ReflectionUtils::isGetter)
                .collect(Collectors.toMap(Function.identity(), (Method method) -> getSetter(method, classType)));

Now it says cannot infer functional interface type.

1 Answers
Related