Java - Java Lambda Expressions Type

Introduction

Consider the lambda expression that takes a String parameter and returns its length:

(String str) -> str.length()

The following is an example of such a functional interface:

@FunctionalInterface
interface StringToIntMapper {
        int map(String str);
}

The lambda expression represents an instance of the StringToIntMapper functional interface.

StringToIntMapper mapper = (String str) -> str.length();

When calling map() method, the body of the lambda expression is executed:

StringToIntMapper mapper = (String str) -> str.length();
String name = "Hi";
int mappedValue = mapper.map(name);
System.out.println("name=" + name + ", mapped value=" + mappedValue);