- Introduction to Lambda
Lambda is added to the JDK as a new feature, explaining Java's support for other languages and absorbing advanced methods in other languages. LAMBDA expressions provide a reference to a type, a reference to a method, and a default method in Java.
The explanation for Lambda is not translated in the wiki Wikipedia to preserve the original flavor (see everyone's understanding, there are different views welcome to explore)
Lambda (programming), a function (or a subroutine) defined, and possibly called, without being bound to an identi Fier
lambda expression in lambda calculus, a formal system in mathematical logic and computer science for expressing C Omputation by the variable binding and substitution
From: http://medianetwork.oracle.com/video/player/3373491280001
2. Example
Import java.util.ArrayList;
Import java.util.Collections;
Import Java.util.Comparator;
Import java.util.List;
public class Lambdaexpresstiontouris {
public static void Main (string[] args) {list<string> ocuppys1 = new arraylist<string> (); Ocuppys1.add ("Bussinessman"); Ocuppys1.add ("Doctor"); Ocuppys1.add ("Teacher"); Ocuppys1.add ("Programer"); Ocuppys1.add ("Stuedent"); list<string> ocuppys2 = new arraylist<string> (); Ocuppys2.add ("Bussinessman"); Ocuppys2.add ("Doctor"); Ocuppys2.add ("Teacher"); Ocuppys2.add ("Programer"); Ocuppys2.add ("Stuedent"); Lambdaexpresstiontouris Letouris = new Lambdaexpresstiontouris (); SYSTEM.OUT.PRINTLN ("Use Java 7 sort:"); System.out.println ("Before:" +ocuppys1); Letouris.sortbyjava7 (OCUPPYS1); System.out.println ("Before:" +ocuppys1); SYSTEM.OUT.PRINTLN ("Use Java 8 sort:"); System.out.println ("Before:" +ocuppys2); Letouris.sortbyjava8 (OCUPPYS2); System.out.println ("Before:" +ocuppys2);} Original sorting method using Java 7 private void SortByJava7 (list<string> liststr) {collections.sort (liststr, New Comparator<sTring> () {public int compare (string s1, string s2) {return s1.compareto (S2); } });} Sort using a Java 8 lambda expression private void sortByJava8 (list<string> liststr) {Collections.sort (Liststr, (S1,S2)-S 1.compareTo (S2));}
}
- Summarize
1,lambda is a function.
2,JAVA8 defines a function interface that is used by the new API
3, Default function method
4, use it to implement a reference to the method
5, use its sort function to implement sorting
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
-----LAMBDA for new features of JAVA8