Lambda function in Java 8 with no parameter and returning value

Viewed 12993

I want to convert a simple Java function to a lambda 8 function without any parameter, and then call it:

public int getMissing() {
  return 0;
}

how to convert above to java8 lambda format?

6 Answers

Define the following:

public interface Function<T> {
    public T apply();
}

With this, you can do something like

methodThatAcceptsFunction(() -> { getMissing(); });
Related