Lambda from the point of use, the first sense of the straightforward understanding is that there is a lot less unnecessary anonymous callback class, such as:
Public Static void Main (string[] args) { new platformquery (). Createdemo (); () , {System.out.println (Jsonutils.tojson (query));}; New Thread (c); Thread.Start (); }
In this code, you will print out:
{"Lists": [{"NodeId": 100001, "nodeName": "Agency 100001", "CompanyID": "" "," CreateDate ":" 20160101 "},{" nodeId ": 100001, "NodeName": "Agency 100001", "CompanyID": "$", "CreateDate": "20160101"}]}
Before Java 8, if we were to start a new thread, we would need to create a new class or an anonymous implementation class, implement the Run () method in the Runnable interface, and then pass a thread as a parameter to complete it.
With lambda, you don't need to create a new class that implements the Runaable interface, which you can do directly in the context of the main thread. where run () is implemented is {System.out.println (Jsonutils.tojson (query)) above,};, () is the signature of the Run method.
From the code's intuitive perspective, it does simplify a lot.
For example, for list ordering, in Java 8, we can use List.sort directly (Comparator) as follows:
Query.getlists (). Sort (new comparator<platform>() { @Override public int Compare (Platform A, Platform b) { return integer.compare (A.getcompanyid (). length (), B.getcompanyid (). Length ()); } );
With lambda expressions, we can use the following two types of notation:
return Integer.compare (A.getcompanyid (). Length (), B.getcompanyid (). Length ());}; Query.getlists (). sort (COM); return Integer.compare (A.getcompanyid (). Length (), B.getcompanyid (). Length ()); }); --This is an example of using anonymous lambda expressions directly
Further, Lambda is able to infer the context automatically, more than the generic compile-time erase (erase), as follows:
return Integer.compare (A.getcompanyid (). Length (), B.getcompanyid (). Length ());}; Query.getlists (). sort (COM1); return Integer.compare (A.getcompanyid (). Length (), B.getcompanyid (). Length ()); });
As can be seen from the above, this is more like the common use of bound events in jquery, and everything is resolved by passing an anonymous function, for Java-based GUI programming or for applications that rely on a wide range of callback functions such as spring JDBC. You can make your code remove a lot of unnecessary skeleton code.
In-depth lambda expression-0 basic one-minute primer