0% found this document useful (0 votes)
23 views1 page

Java 8 Lambda Expressions Explained

Lambda expressions in Java 8 allow functionality to be treated as a method argument or code as data. They enable creating a function without belonging to any class. A lambda expression can be passed around and executed on demand. The document provides an example of a functional interface with a single abstract method and a lambda expression implementing that interface. The expression is called and prints double the value passed, demonstrating lambda expressions in Java 8.

Uploaded by

XYZ Kumar
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views1 page

Java 8 Lambda Expressions Explained

Lambda expressions in Java 8 allow functionality to be treated as a method argument or code as data. They enable creating a function without belonging to any class. A lambda expression can be passed around and executed on demand. The document provides an example of a functional interface with a single abstract method and a lambda expression implementing that interface. The expression is called and prints double the value passed, demonstrating lambda expressions in Java 8.

Uploaded by

XYZ Kumar
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

28/05/2018 Lambda Expressions in Java 8 - GeeksforGeeks

Lambda Expressions in Java 8


Lambda expressions basically express instances of functional interfaces(An interface with single abstract
method is called functional interface. An example is [Link]). lambda expressions implement
the only abstract function and therefore implement functional interfaces

lambda expressions are added in Java 8 and provide below functionalities.

Enable to treat functionality as a method argument, or code as data.


A function that can be created without belonging to any class.
A lambda expression can be passed around as if it was an object and executed on demand.

// Java program to demonstrate lambda expressions
// to implement a user defined functional interface.
 
// A sample functional interface (An interface with
// single abstract method
interface FuncInterface
{
    // An abstract function
    void abstractFun(int x);
 
    // A non­abstract (or default) function
    default void normalFun()
    {
       [Link]("Hello");
    }
}
 
class Test
{
    public static void main(String args[])
    {
        // lambda expression to implement above
        // functional interface. This interface
        // by default implements abstractFun()
        FuncInterface fobj = (int x)­>[Link](2*x);
 
        // This calls above lambda expression and prints 10.
        [Link](5);
    }
}
Run on IDE

Output:

10

Syntax:
[Link] 1/4

You might also like