Android studio configuring lambda expressions tutorial

One of the highlights of Java 8 is the introduction of lambda expressions, which will make the code designed more concise. When developers write lambda expressions, they will also be compiled into a functional interface.

However, the current Android studio does not support the new features of Java 8, so in order to use it, we can only save the country with the help of retroambda

1. Upgrade your JDK to 1.8, and then configure the environment

2. Update your SDK to 24

3. Configure the address of retrorambda plug-in in the project gradle file of the project:

As follows:

Remove the quoted sentence when you add it yourself

3. Add the following at the top of the module gradle file of the project:

4. Add in the Android closure of the modu gradle file of the project

In this way, we can use lambda expressions in Android studio.

For example:

Using lambda:

Another example is using threads:

Using lambda:

As you can see, using lambda expressions not only makes the code simple, but also readable, and most importantly, the amount of code is greatly reduced. So use it!

The above is the Android studio configuration lambda expression tutorial introduced by Xiaobian. I hope it will help you. If you have any questions, please leave me a message and Xiaobian will reply to you in time!

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>