Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/370.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
lambda-map-java8中的类类型_Java_Dictionary_Lambda_Java Stream_Collectors - Fatal编程技术网

lambda-map-java8中的类类型

lambda-map-java8中的类类型,java,dictionary,lambda,java-stream,collectors,Java,Dictionary,Lambda,Java Stream,Collectors,我有一个方法签名,用于基于给定的getter方法类型method使用反射来获取setter方法。 该方法的签名如下: Method getSetter(final Method getterMethod, final Class classType) final Method[] methods = classType.getMethods(); Stream.of(methods) .filter(ReflectionUtils::isGett

我有一个方法签名,用于基于给定的getter方法类型method使用反射来获取setter方法。 该方法的签名如下:

Method getSetter(final Method getterMethod, final Class classType)
final Method[] methods = classType.getMethods();
        Stream.of(methods)
                .filter(ReflectionUtils::isGetter)
                .collect(Collectors.toMap(Function.identity(), (method) -> getSetter(method, classType)));
现在从一个类的方法开始,我想要一个getter方法到相关setter方法的映射。我的代码如下:

Method getSetter(final Method getterMethod, final Class classType)
final Method[] methods = classType.getMethods();
        Stream.of(methods)
                .filter(ReflectionUtils::isGetter)
                .collect(Collectors.toMap(Function.identity(), (method) -> getSetter(method, classType)));
我在getSetter(方法,类类型)处遇到编译错误 它说找到了错误的第一个类型参数:
,必需:
java.lang.reflect.Method

我还尝试指定lambda参数的类型。见下文

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

现在它说不能推断函数接口类型。

您的代码可以与javac 8u25、u40、u60、u71以及ecj 3.10.2配合使用。这里唯一的问题是发出警告的原始
Class
参数。它应该用
参数化:

methodgetsetter(finalmethodgettermethod,finalclass类类型){…}

我无法复制这个。请检查您的导入,指定Java的确切版本以及您使用的编译器。嘿,谢谢!!实际上,对于getSetter方法,我抛出了NoSuchMethodException,我应该创建一个try-catch块。我变了。成功了。