Jon*_*her 5 java lambda checkstyle
以这个 Lambda 为例:
final List<String> badKeys = pivMap.entrySet().stream()
.filter(entry -> StringUtils.trimToNull(entry.getValue()) == null || entry.getValue().equals("{}") || entry.getValue().equals("{ }"))
.map(Map.Entry::getKey)
.collect(Collectors.toList());
Run Code Online (Sandbox Code Playgroud)
我们要确保 Lambda 变量上有一个显式类型:
final List<String> badKeys = pivMap.entrySet().stream()
.filter((final Map.Entry<String, String> entry) -> StringUtils.trimToNull(entry.getValue()) == null || entry.getValue().equals("{}") || entry.getValue().equals("{ }"))
.map(Map.Entry::getKey)
.collect(Collectors.toList());
Run Code Online (Sandbox Code Playgroud)
有没有办法使用 puppycrawl checkstyle 来检查上面的 lambda 表达式是否存在类型?在这种情况下,变量的类型声明是:(final Map.Entry<String, String> entry)