- Functional interfaces introduces in java 8 .
- Functional interfaces will have single abstract method in it.
- Check here for full details on Java 8 functional interface with example.
- Functional interfaces will be implemented by java 8 Lamda expressions.
- Lets see an example program on how can we use functional interfaces or how can we implement functional interfaces using Lamda expression in java 8.
- Create one functional interface with one abstract method in it.
- Create a class and implement this abstract method using Lamda Expressions.
#1: Java example program to create functional interface.
#2: Java example program to implement functional interface using Lamda expressions in java 8.
- package com.instanceofjava.java8;
- /**
- * @author www.Instanceofjava.com
- * @category interview programming questions
- *
- * Description: java 8 Lamda expressions
- *
- */
- public class LamdaExpressions {
- public static void main(String[] args) {
- FunctionalInterfaceExample obj = ()->{
- System.out.println("hello world");
- };
- obj.show();
- }
- }
Output:
- hello world
No comments