OO Programming with Java


Advanced Concepts

Complement 1. BiFunction are functions with two arguments:

import java.util.function.*;
public class Funs {
  public static void main(String[] args) {
    BiFunction<Integer,Integer,Integer> sum = (x,y) -> x+y;
    System.out.println( sum.apply(3,-6) );
  }
}

Comparators are binary predicates:

import java.util.*;
public class Funs {
  public static void main(String[] args) {
    Comparator<Integer> inf = (x,y)->x.compareTo(y); // { -1, 0, 1 }
    System.out.println( inf.compare(3,-3) );
  }
}

7 - 17