After long time I again found my old craze to write on Technical
things. So today’s topic is Lambda Expression Java 8 which is very much
hyped now a days.
Here are some important points for Lambda Expression:
Javac looks for information close to your Lambda Expression and use this information to figure out what would be correct type. It still typed checked and provide all the safety that you are used to, but you don’t have to state or write the types explicitly. This is called Type Inference.
Okey, today I am trying to approach new fundamentals for technologies and delivering in the form of notes. Feel free to comments or ask questions it will motivate me to indulge more with you ;)
Here are some important points for Lambda Expression:
Lambda Expression Java 8
- The target type of Lambda Expression is the type of the context in which the Lambda Expression appears.
For Example: A local variable that it’s assigned to or a method parameter that it’s gets passed into. - Although you haven’t declare the variable as final you still can’t use them as non-final variable. If they are to be used in Lambda Expression. If you do use them as a non-final variables, then the compiler will show as error.
- Lambda Expression capture values not variables.
- Lambda Expression are statically typed, so lets investigate the types of Lambda Expressions themselves. These types are called Functional interfaces.
- A functional interface is an interface with a single abstract method that is used as the type of a Lambda Expression.
Interface | Arguments | Return |
Predicate |
T | Boolean |
Consumer |
T | Void |
Function |
T | R |
Supplier |
None | T |
Unary Operator |
T | T |
Binary Operator |
(T,T) | T |
- In the same way that Java 7 allowed to leave out the generic types for a constructor. Java 8 allows to leave out the types for whole parameters of Lambda Expression.
Javac looks for information close to your Lambda Expression and use this information to figure out what would be correct type. It still typed checked and provide all the safety that you are used to, but you don’t have to state or write the types explicitly. This is called Type Inference.
Okey, today I am trying to approach new fundamentals for technologies and delivering in the form of notes. Feel free to comments or ask questions it will motivate me to indulge more with you ;)
No comments:
Post a Comment