Java 8, Lambda : 用 lambda 替换 Anonymous inner class
我有一个包含以下内容的类:
List roles = ldapTemplate.search(baseDn, replaceFilter, sc,
new AttributesMapper() {
public Object mapFromAttributes(Attributes attrs)
throws NamingException {
return attrs.get("cn").get();
}
});
IntelliJ 告诉我用 lambda 替换匿名内部类。所以我尝试了:
List roles = ldapTemplate.search(
baseDn, replaceFilter, sc,
(Attributes a) -> { return a.get("cn").get(); };
);
但是,我收到编译错误:
Error:(46, 50) java: incompatible types: inference variable T has incompatible bounds
equality constraints: java.lang.String
lower bounds: java.lang.Object
我找不到这个问题的解决方案。你有什么想法吗?