2 ms·
Good examples of closures / first order functions in java is through a visitor; example below is like the ones in A Little Java, A Few Patterns new Top(new Anc
by cconroy 15y ago
Good examples of closures / first order functions in java is through a visitor; example below is like the ones in A Little Java, A Few Patterns
new Top(new Anchovy(),
new Top(new Tuna(),
new Top(new Lettuce(), new Bot())))
.accept( new RemVisitor(new Anhovy() );
This removes those smelly Anchovies from your tuna sandwich -- and can be implemented with a closure or not. If accept() method returns a new Top w/o Anchovies and RemoveVisitor stores what to remove in its field then it is a closure.
This book is cool for lisp programmers to learn programming with recursive objects like composites and decorators.