November 2018
Intermediate to advanced
388 pages
9h 5m
English
Java 8 introduced lambda expressions, which are geared toward the functional programming paradigm. With lambda expressions, we can write higher-order functions, which means we can pass a function to another function. Lambda expressions can be applied to interfaces with a single abstract method, which are known as SAM interfaces.
Before Java 8, when we wanted to use the SAM interface or the functional interface, we had to write an anonymous inner class, which requires a lot of verbose code. For example, let's write a SAM interface:
@FunctionalInterfaceinterface Greet { fun hello(str: String): String}
To use the interface type as a method argument, we need to use the anonymous inner class, as shown here: ...
Read now
Unlock full access