MyEclipse,【Lambda expressions are allowed only at source level 1.8 or above】编译错误的解决

问题:

因工作需要,在MyEclipse现有项目中导入一段代码,代码片段引用了Lambda表达式,如下:

    @Test
    public void test01() throws IOException {
        DeptMapper deptMapper = session.getMapper(DeptMapper.class);
        Dept dept = new Dept();
        dept.setDeptno(2);
        dept.setDname("test2");
        List<Dept> list = deptMapper.findList1(dept);
        list.forEach(item -> System.out.println(item));
    }

编译时出错:【Lambda expressions are allowed only at source level 1.8 or above】

解决:

鼠标右键单击项目属性【Properties】,在出现的窗口中,选择【Java Compiler】,将【Compiler  compliance Level】改为1.8以上即可。如下图:

 

posted @ 2021-08-22 11:32  那些年的事儿  阅读(1572)  评论(0编辑  收藏  举报