Functional interface in Java

Quick example

/**
 * Declare our functional interface
 */
@FunctionalInterface
public interface CustomLogger {
    public void log(String message);
}

class Demo {
    public static String message = "Hello World!";

    public static logMessage(CustomLogger customLogger) {
        customLogger.log(message);
    }
}

Demo.logMessage(message -> {
    System.out.println(message);
});

Leave a Reply

Your email address will not be published. Required fields are marked *