Functional Interface in Java
Code Green

Code Green @codegreen

About: Cloud Native Dev | Android Dev | Automation Tester

Location:
India
Joined:
Feb 20, 2021

Functional Interface in Java

Publish Date: Jul 4 '24
1 0

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");
    }
}
Enter fullscreen mode Exit fullscreen mode

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.

Comments 0 total

    Add comment