当前位置: 代码迷 >> 综合 >> 【J2SE】IntelliJ IDEA中Lambda表达式警告:Can be replaced with method reference less
  详细解决方案

【J2SE】IntelliJ IDEA中Lambda表达式警告:Can be replaced with method reference less

热度:60   发布时间:2023-12-17 13:49:21.0

IntelliJ IDEA中Lambda表达式警告:Can be replaced with method reference less

Can be replaced with method reference less… (Ctrl+F1) This
inspection reports lambdas which can be replaced with method
references Lambda/method references syntax is not supported under Java
1.7 or earlier JVMs.

代码如下

    @Testpublic void test() {ArrayList<String> strings = new ArrayList<>();strings.add("1");strings.add("2");strings.add("3");strings.add("4");strings.forEach((String str)-> System.out.println(str));}

IDEA_Lambda

应该把爆警告的那句话修改成

strings.forEach(System.out::println);

IDEA_Lambda_2

无警告多清爽!

  相关解决方案