Lambda - JavaMasterClass/JavaMasterClass.github.io GitHub Wiki
Functional Interface
- A lambda function implements a Functional Interface
- A functional interface:
- have only one abstract method.
- have as many default, static methods.
- can have methods from object class.
- @FunctionalInterface may be used on functional Interface.
Define functional interface
@FunctionalInterface
public interface Supplier<T> {
T get();
}Implement
Supplier<String> supplier = () -> "Hello World!";Call
System.out.printf("%s %s", "Output", supplier.get());- Avoid Auto-boxing, Auto-unboxing