// functional/TriFunction.java
// (c)2017 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.
@FunctionalInterface
public interface TriFunction<T, U, V, R> {
R apply(T t, U u, V v);
}
test above code:
// functional/TriFunctionTest.java
// (c)2017 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.
public class TriFunctionTest {
static int f(int i, long l, double d) {
return 99;
}
public static void main(String[] args) {
TriFunction<Integer, Long, Double, Integer> tf = TriFunctionTest::f;
tf = (i, l, d) -> 12; // [1]
System.out.println(tf);
System.out.println(tf.apply(1, 1L, 1.1));
}
}
/* My Output:
TriFunctionTest$$Lambda$2/1915318863@4c873330
12
*/
when change [1] to
tf = (i, l, d) -> System.out.println(123);
It shows compile error:
functional/TriFunctionTest.java:13: error: incompatible types: bad return type in lambda expression
tf = (i, l, d) -> System.out.println("123");
^
void cannot be converted to Integer
1 error
references:
1. On Java 8 - Bruce Eckel
3. https://github.com/wangbingfeng/OnJava8-Examples/blob/master/functional/TriFunction.java
4. https://github.com/wangbingfeng/OnJava8-Examples/blob/master/functional/TriFunctionTest.java