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
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/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.