Java – What is Functional Interface

To create a functional interface

You may come across codes like this ()->{ System.out.println("Hello World"); }, a bracket first then follow by an arrow, if you have ever written JavaScript before, it is known as arrow function in JavaScript. In Java land this is known as functional interface.

To create a functional interface, all you have to do is create an interface with a SAM(Single Abstract Method), and then put a @FunctionalInterface annotation to the interface.
public interface SimpleFuncInterface {
  public void execute();

To implement Functional Interface
* Implementing the interface by creating an
* anonymous inner class versus using 
* lambda expression.
public class SimpleFunInterfaceTest {
  public static void main(String[] args) {
    carryOutWork(new SimpleFuncInterface() {
      public void execute() {
        System.out.println("Do work in SimpleFun impl...");
    carryOutWork(() -> System.out.println("Do work in lambda exp impl..."));
  public static void carryOutWork(SimpleFuncInterface sfi){
Do work in SimpleFun impl...
Do work in lambda exp impl...

Author: Wu Chia Chong

My main areas of interest are software architectures and software design methods, patterns, and new trends in software development.