Skip to content
Anuj Jain edited this page Jan 15, 2021 · 3 revisions

Lambda (Java 8+)

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.

Function interface examples

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());

Lambda Performance

  • Avoid Auto-boxing, Auto-unboxing
Clone this wiki locally