Functional Interface in Java

Functional Interface in Java

A functional interface in Java is an interface that contains exactly one abstract method. It can have any number of default methods or static methods.

Syntax: Declared using the @FunctionalInterface annotatio…


This content originally appeared on DEV Community and was authored by Manish Thakurani

Functional Interface in Java

A functional interface in Java is an interface that contains exactly one abstract method. It can have any number of default methods or static methods.

  • Syntax: Declared using the @FunctionalInterface annotation.
  • Example:
@FunctionalInterface
public interface MyFunctionalInterface {
    void abstractMethod();

    default void defaultMethod() {
        System.out.println("Default method implementation");
    }

    static void staticMethod() {
        System.out.println("Static method implementation");
    }
}

Conclusion: Functional interfaces are the foundation of functional programming in Java, facilitating the use of lambda expressions and method references. They promote concise and readable code by allowing methods to be treated as first-class citizens.


This content originally appeared on DEV Community and was authored by Manish Thakurani


Print Share Comment Cite Upload Translate Updates
APA

Manish Thakurani | Sciencx (2024-07-04T15:09:00+00:00) Functional Interface in Java. Retrieved from https://www.scien.cx/2024/07/04/functional-interface-in-java/

MLA
" » Functional Interface in Java." Manish Thakurani | Sciencx - Thursday July 4, 2024, https://www.scien.cx/2024/07/04/functional-interface-in-java/
HARVARD
Manish Thakurani | Sciencx Thursday July 4, 2024 » Functional Interface in Java., viewed ,<https://www.scien.cx/2024/07/04/functional-interface-in-java/>
VANCOUVER
Manish Thakurani | Sciencx - » Functional Interface in Java. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2024/07/04/functional-interface-in-java/
CHICAGO
" » Functional Interface in Java." Manish Thakurani | Sciencx - Accessed . https://www.scien.cx/2024/07/04/functional-interface-in-java/
IEEE
" » Functional Interface in Java." Manish Thakurani | Sciencx [Online]. Available: https://www.scien.cx/2024/07/04/functional-interface-in-java/. [Accessed: ]
rf:citation
» Functional Interface in Java | Manish Thakurani | Sciencx | https://www.scien.cx/2024/07/04/functional-interface-in-java/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.