Java 8 new features-functional interfaces

Source: Internet
Author: User

A core concept introduced in Java 8 is the functional interface (functional Interfaces).

By adding an abstract method to the interface, these methods can be run directly from the interface.

If an interface defines a unique abstract method , then this interface becomes a functional interface .

At the same time, a new annotation was introduced:@FunctionalInterface.

Can put him in front of an interface, indicating that this interface is a functional interface.

This annotation is not necessary , as long as the interface contains only one method interface, the virtual opportunity is automatically judged, but it is best to use annotations @FunctionalInterface on the interface to declare.

  A @FunctionalInterface interface is added to the interface, only one abstract method is allowed, or the compiler will error .

Java.lang.Runnable is a function-type interface.

 Package Java.lang; @FunctionalInterface  Public Interface Runnable {    void  run ();}

Quoted from: Https://www.ibm.com/developerworks/cn/java/j-lo-jdk8newfeature/

Java 8 new features-functional interfaces

Related Article

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.