- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What is the data type of a lambda expression in Java?
The lambda expressions have a very simple, precise syntax and provide flexibility to specify the datatypes for the function parameters. Its return type is a parameter -> expression body to understand the syntax, we can divide it into three parts.
- Parameters : These are function method parameters and match with the signature of a function defined in the functional interface. Defining the data-type of parameters is optional but the number of parameters can match with the defined signatures in the interface.
- Expression Body : This is either a single statement or collection of statements that represent the function definition. Defining the data-type for return object is optional.
- -> : This represents the lambda expression operator.
Example
interface Hello { String sayHello(String name); } public class LambdaExpressionTest { public static void main(String args[]) { Hello hello = (message) -> { String str1 = "Hello "; String str2 = str1 + message; return str2; }; System.out.println(hello.sayHello("Tutorials Point")); } }
Output
Hello Tutorials Point
Advertisements