OO Programming with Java


Advanced Concepts

b. Sample:

  public static <X> X print(X x) // transform 'println' into a function
    { System.out.print(x+" "); return x; }
  
  public static void main(String[] args) {
	Tree<Integer> e = new Tree.Leaf();
	Tree<Integer> t = 
	  new Tree.Node(
		new Tree.Node(e,1,e), 
		3, 
		new Tree.Node(
		  new Tree.Node(e,4,e),
		  5,e));
	t.map(Funs::print);
  }

16 - 17