OO Programming with Java


Advanced Concepts

  1. Function is associated to a specific notation:
import java.util.function.*;
public class Funs {
  public static void main(String[] args) {
    Function<Integer,Integer> abs = x -> (x>=0)?x:-x;
    System.out.println(abs.apply(-3));
  }
}

The -> is called a 'lambda' expression and comes from a theoritical model of computer science: the lambda calculus proposed by Alonzo Church as an alternative to Turing machines (1930).


6 - 17