Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android studio : lambda expressions are not supported in -source 1.7 (use -source 8 or higher to enable lambda expressions) [duplicate]

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

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

enter image description here

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

enter image description here

Which resulted in something below:

enter image description here

After running the code it showed me this error:

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

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

Can anyone help me out please..

like image 743
Chintan Soni Avatar asked May 18 '15 02:05

Chintan Soni


2 Answers

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

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.

like image 109
Stepango Avatar answered Sep 20 '22 05:09

Stepango


I don't think Android development is ready yet for Java 8. Android Studio supports the compile level Java 7 whether you installed Java 7 or Java 8. So, if you want to use new features of Java 8, I think you have to wait Android Studio to support compile level Java 8.

like image 41
SilentKnight Avatar answered Sep 24 '22 05:09

SilentKnight