In Java
Java has no first-class functions, so function objects are usually expressed by an interface with a single method (most commonly the Callable
interface), typically with the implementation being an anonymous inner class.
For an example from Java's standard library, java.util.Collections.sort
takes a List
and a functor whose role is to compare objects in the List. Without first-class functions, the function is part of the Comparator interface. This could be used as follows.
Read more about this topic: Function Object