Friday, 15 June 2018

Lambda Expression Java

A Lambda expression (or function) is just an anonymous function, i.e., a function with no name and without being bounded to an identifier. They are written exactly in the place where it’s needed, typically as a parameter to some other function.

Syntax:

either
(parameters) -> expression
or
(parameters) -> { statements; }
or
() -> expression

Example:

package lambda;


public class Two {
    public static void main(String args[]) {
        new Thread(new Runnable() {
           
            @Override
            public void run() {
                // TODO Auto-generated method stub
                System.out.println("hello runnable");
            }
        }).start();
       
        new Thread(()-> System.out.println("hello lambda runnable")).start();
       
    }
}


Ref: https://howtodoinjava.com/java-8-tutorial/

No comments:

Post a Comment

links for Data Structure

  1) 𝐁𝐞𝐜𝐨𝐦𝐞 𝐌𝐚𝐬𝐭𝐞𝐫 𝐢𝐧 𝐋𝐢𝐧𝐤𝐞𝐝 𝐋𝐢𝐬𝐭:  https://lnkd.in/gXQux4zj 2) 𝐀𝐥𝐥 𝐭𝐲𝐩𝐞𝐬 𝐨𝐟 𝐓𝐫𝐞𝐞 𝐓𝐫𝐚𝐯𝐞𝐫𝐬𝐚𝐥𝐬...