As mentioned in the previous article, callback is actually a more fundamental concept in functional programming. Now let's take a look at how functional programming is implemented in Java.
First, let's take a look at a piece of code that is familiar to Java:
// Interface class, which should be regarded as a part of functional programming. Public interface actionlistener {public void actionreceivmed (actionevent E);} class xlistener implements actionlistener {public void actionreceivmed (actionevent e) {// action here} xlistener L = new xlistener (); iexit. addactionlistener (L );
But in fact, this implementation method is redundant. In fact, it can be implemented using anonymous classes. In Java, the anonymous class is the idea of functional programming. Let's take a look.
Iexit. addactionlistener (New actionlistener () {public void actionreceivmed (actionevent e) {// action here }});
In JavaScript, the following method is available:
$ ("# Element "). click (function () {// do something}); $ ("Div. type "). each (function (INDEX) {// do something else with the index });
Reprinted from: http://www.iteye.com/topic/539515