Lambda expressions for jdk1.8 new features and examples of use in Android Studio

Source: Internet
Author: User

Jdk1.8 has been out for a long time, but many students may not be familiar with the application of its features in Android Studio, and today we are going to do its application to this new feature in as.

First, in the case of JDK1.8, we will set this place to java1.8 in the settings of AS.

Second, add these two sentences to the Build.gradle.

That

compileoptions {
Sourcecompatibility 1.8
Targetcompatibility 1.8
}

This completes the setup work before you use it. Then we go into the important application.

So what's the nature of lambda? See below:

1. This is a click event set for a button:

What, frugality is not a lot of savings, from the previous 6 lines into 1 lines, and easier to let others understand.

2. Here is the code to open a thread

So how to change the code into a lambda style, in fact, after the setup to put the mouse on the function, Alt+enter will appear under the following interface, and then click on it.

The properties of Lambda We're going to introduce so much for the moment.

Follow the public number for more information:

Lambda expressions for jdk1.8 new features and examples of use in Android Studio

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.