Functional interface Functional interface An Interface that contains
- Slides: 14
Functional interface
Functional interface An Interface that contains exactly one abstract method is known as functional interface. It can have any number of default, static methods but can contain only one abstract method.
A functional interface can extends to other interface only when that does not have any abstract method.
Functional interface (extending non-functional interface)
Lambda expression
Lambda expression is a new and important feature of Java which was included in Java SE 8. It provides a clear and concise way to represent one method interface using an expression. It is very useful in collection library. It helps to iterate, filter and extract data from collection. Before lambda expression, anonymous inner class was the only option to implement the method. In other words, we can say it is a replacement of java inner anonymous class. Java lambda expression is treated as a function, so compiler does not create. class file. Lambda expression provides implementation of functional interface. An interface which has only one abstract method is called functional interface.
A lambda expression can have zero or any number of arguments. Let's see the examples:
Example (passing lambda expression as method argument)
(String name) -> { return “Hello” + name; } You can omit the data-type of arguments as: (name) -> { return “Hello” + name; }
Addable ad = (a, b) -> { return a+b; }; You can omit return for single statement, but then the statement must be written in brackets (), rather than braces {}. Eg: a+b and “Red” have to be written as: (a+b) and (“Red”) respectively. Addable ad = (a, b) -> (a+b);
In Java lambda expression, if there is only one statement, you may or may not use return keyword. You must use return keyword when lambda expression contains multiple statements.
- Thơ thất ngôn tứ tuyệt đường luật
- Tôn thất thuyết là ai
- Phân độ lown ngoại tâm thu
- Chiến lược kinh doanh quốc tế của walmart
- Gây tê cơ vuông thắt lưng
- Premature atrial contraction
- Tìm độ lớn thật của tam giác abc
- Sau thất bại ở hồ điển triệt
- Thể thơ truyền thống
- Hãy nói thật ít để làm được nhiều
- Cantilever type space maintainer
- Non functional plasma enzymes
- Enzymes
- Functional and non functional
- Functional mockup interface