interface Lazy { T eval(); } class Memo implements Lazy { T memorandum = null; Lazy work; Memo( Lazy w ) { work = w; } public T eval() { if (work != null) { memorandum = work.eval(); work = null; } return memorandum; } } public class Demo { public static void main(String[] args) { Lazy a = ()-> 1; for (int i = 1; i <= 30; i++) { Lazy b = a; a = new Memo( ()-> b.eval() + b.eval() ); } System.out.println( "= " + a.eval() ); } }