Definition:
A function interface in java is an interface with a single abstract method. They are used to type lambda expressions.
Example:
In the following example, 'Cat' is a functional interface.
A function interface in java is an interface with a single abstract method. They are used to type lambda expressions.
Example:
In the following example, 'Cat' is a functional interface.
interface Cat {
void meow();
}
public static void main(String... args) {
Cat cat = () -> System.out.println("Meowwwwww");
cat.meow();
}
It is good practice to annotate functional interfaces with the annotation @FunctionalInterface .
No comments:
Post a Comment