我正在测试Java 8的一些新特性,并将示例复制到我的IDE(最初是Eclipse,然后是IntelliJ),如下所示

Eclipse对lambda表达式不提供任何支持,IntelliJ不断报告错误

此语言级别不支持Lambda表达式

我想知道这是否是我的安装、代码或支持的问题。


当前回答

如果你得到了语言5不支持,检查这个:( 对我来说,它是在模块部分)

其他回答

此解决方案适用于Android Studio 3.0或更高版本。

文件>项目结构>模块>应用>属性选项卡

将Source Compatibility和Target Compatibility都更改为1.8

编辑配置文件

您也可以在相应的版本中直接配置它。gradle文件

android {
  ...
  // Configure only for each module that uses Java 8
  // language features (either in its source code or
  // through dependencies).
  compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
  }
}

文件>项目结构>模块>源选项卡>修改语言级别为8

实际上,Eclipse对Java 8的支持是可用的:请参见这里和这里。

对于开普勒来说,它是针对SR2(即Eclipse 4.3.2)的“功能补丁”。 对于Luna (Eclipse 4.4),它将出现在标准发行版中。(发布时间表)

这个答案对新更新的intelliJ不起作用…为了新智能…

进入——> file——> Project Structure——> Global Libraries ==>设置为JDK 1.8或更高版本。

also File——> project Structure——> projects ===> set "project language manual" = 8

——>项目结构——>项目sdk ==>

这将为您的项目启用lambda表达式。

在intellij 14中,以下设置对我有效。 Intellij14设置