IntelliJ IDEA中Lambda表達式警告:Statement lambda can be replaced with expression lambda

今天寫一個小玩意的時候由於FileFilter是個函數式接口就想着直接用lambda表達式寫,寫完,idea報出了個警告java

Statement lambda can be replaced with expression lambda less… (Ctrl+F1)
This inspection reports lambda expressions with code block bodies when expression-style bodies can be us

warning的地方在這裏express

if (file.isDirectory()) {
                    File[] files = file.listFiles((file2)-> {
                        return file2.getName().contains(name);
                    });
                    for (File file1 : files) {
                        System.out.println(file1.getName());
                    }
                }

發現只要改爲這樣行,更簡潔less

相關文章
相關標籤/搜索