- Trending Categories
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
- Related Articles
- What is a target type of lambda expression in Java?
- Type Inference in Lambda expression in Java?
- What is Lambda expression in C#?
- Lambda expression in Java 8
- What is a lambda expression in C++11?
- What are the rules for the body of lambda expression in Java?
- What kind of variables can we access in a lambda expression in Java?
- How to write a conditional expression in lambda expression in Java?
- What are the rules for a local variable in lambda expression in Java?
- What are the rules for formal parameters in a lambda expression in Java?
- Java Lambda Expression with Collections
- Importance of Predicate interface in lambda expression in Java?
- How to write the comparator as a lambda expression in Java?
- What is the lambda expression to convert array/List of String to array/List of Integers in java?
- How to declare a variable within lambda expression in Java?

Advertisements