我有以下代码:
PropertyDescriptor[] propertyDescriptors = Introspector.getBeanInfo(Mailingadresse.class).getPropertyDescriptors();
Map<String, PropertyDescriptor> m = Arrays
.stream(propertyDescriptors)
.filter(pd -> pd.getReadMethod() != null)
.collect(Collectors.toMap(pd -> pd.getName().toLowerCase(), Function::identity));
Eclipse 显示
The method toMap(Function, Function) in the type Collectors is not applicable for the arguments (( pd) -> {}, Function::identity)
这是为什么?
最佳答案
Function.identity()
返回一个函数式接口(interface)(Function
),所以不需要方法引用,需要调用方法:
PropertyDescriptor[] propertyDescriptors = Introspector.getBeanInfo(Mailingadresse.class).getPropertyDescriptors();
Map<String, PropertyDescriptor> m = Arrays
.stream(propertyDescriptors)
.filter(pd -> pd.getReadMethod() != null)
.collect(Collectors.toMap(pd -> pd.getName().toLowerCase(), Function.identity()));
关于java - PropertyDescriptors 数组上 Stream 的 toMap() 函数中出现编译错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46175786/