| 4 | import java.util.function.BiFunction; |
| 5 | |
| 6 | public class FunctionalInterfaces { |
| 7 | |
| 8 | /** |
| 9 | * A functional interface such as Function class takes two generic types, the |
| 10 | * type of the input and the type of the output. They can be written as |
| 11 | * anonymous classes that implement the Function interface, but they are more |
| 12 | * commonly written as lambda functions. |
| 13 | * |
| 14 | */ |
| 15 | static Function<String, String> sayHello = name -> "Hello, " + name; |
| 16 | |
| 17 | /** |
| 18 | * A BiFunction works the same way as a Function,except for taking two input |
| 19 | * types |
| 20 | */ |
| 21 | static BiFunction<Integer, Integer, Integer> sumValues = (x, y) -> x + y; |
| 22 | |
| 23 | public static void main(String[] args) { |
| 24 | // Function types are invoked using the .apply() method on the interface |
| 25 | System.out.println(sayHello.apply("Dan")); |
| 26 | System.out.println(sumValues.apply(3, 2)); |
| 27 | } |
| 28 | } |
nothing calls this directly
no outgoing calls
no test coverage detected