android studio:-source 1.7不支持lambda表达式(使用-source 8或更高版本以启用lambda表达式) [英] android studio : lambda expressions are not supported in -source 1.7 (use -source 8 or higher to enable lambda expressions)

查看:445
本文介绍了android studio:-source 1.7不支持lambda表达式(使用-source 8或更高版本以启用lambda表达式)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

很高兴知道Java在Java中引入了 Lambda表达式版本8.

Happy to know that java introduced Lambda expressions in java version 8.

我在android studio中工作.而且我注意到DialogInterface.OnClickListener()出现下划线并变成灰色,如下所示:

I was working in android studio. And I noticed that DialogInterface.OnClickListener() was showing underline and became grey colored as below:

因此,我在该行上做了alter + enter,并找到了将代码替换为Lambda表达式的选项,如下所示:

So, I did alter + enter on that line and found option to replace the code with Lambda Expressions, as below:

这导致以下结果:

运行代码后,它向我显示此错误:

After running the code it showed me this error:

错误:(160,69)错误:-source不支持lambda表达式 1.7(使用-source 8或更高版本启用lambda表达式)

Error:(160, 69) error: lambda expressions are not supported in -source 1.7 (use -source 8 or higher to enable lambda expressions)

但是我已经在使用Java jdk1.8.0_31.还有什么我需要安装的吗?

But I am already using java jdk1.8.0_31. Is there anything else, I need to install ?

任何人都可以帮我吗..

Can anyone help me out please..

推荐答案

您无法为Android编译Java 8源,因为Android SDK尚不支持Java 8.

You cannot compile Java 8 sources for Android, because Android SDK does not support Java 8 yet.

但是有一种在代码中使用Lambda的方法- RetroLambda .这是一个小技巧,可让您在项目中使用Java 8的某些功能.

But there is one way to use Lambdas in your code - RetroLambda. This is a little hack that allows you to use some of the features of Java 8 in your project.

这篇关于android studio:-source 1.7不支持lambda表达式(使用-source 8或更高版本以启用lambda表达式)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆