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

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.

代码如下

    @Test
    public 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

无警告多清爽!

阅读更多
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/R3lish/article/details/51814580
文章标签: lambda intellij idea
个人分类: J2SE
上一篇【Android死丢丢】在AndroidStudio中使用Lambda表达式
下一篇【Android单元测试】如何在InstrumentationTestCase中获取Context对象
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭
关闭