問題:
因工作需要,在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以上即可。如下圖: