MCPcopy Create free account
hub / github.com/PrajaktaSathe/Java / FunctionalInterfaces

Class FunctionalInterfaces

Programs/FunctionalInterfaces.java:6–28  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4import java.util.function.BiFunction;
5
6public 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}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected