- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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 a target type of lambda expression in Java?
A functional Interface for which a lambda expression has invoked is called target type of lambda expression. It means that if a lambda expression has invoked for some "X" interface then "X" is the target type of that lambda expression. Hence, we conclude that lambda expressions can be used only in those situations where java compiler can determine the Target Type.
In the below example, the target type of lambda expression is BiFunction. An instance of a class is automatically created that implements the functional interface and lambda expression provides an implementation of the abstract method declared by the functional interface.
Example
interface BiFunction { R apply(K k , V v); } public class LambdaTypeInferenceTest { public static void main(String[] args) { BiFunction result = (n1, n2) -> { return n1 + n2;}; // lambda expression Integer n1 = 10; Integer n2 = 20; System.out.println("The addition of n1 and n2 is: "+ result.apply(n1, n2)); } }
Output
The addition of n1 and n2 is: 30
- Related Articles
- What is the data type of a lambda expression in Java?
- Type Inference in Lambda expression in Java?
- What is Lambda expression in C#?
- What is a lambda expression in C++11?
- Lambda expression in Java 8
- How to write a conditional expression in lambda expression in Java?
- What kind of variables can we access in a lambda expression in Java?
- Java Lambda Expression with Collections
- Importance of Predicate interface in lambda expression in Java?
- What are the rules for the body of 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?
- How to declare a variable within lambda expression in Java?
- How to reverse a string using lambda expression in Java?
- How can we write a multiline lambda expression in Java?

Advertisements