- Functional interfaces in java 8 will have single abstract method in it.
- Check below two pages regarding defining and using functional interfaces using Lamda expressions.
- Java 8 functional interface with example
- Implement java 8 functional interface using lambda example program
- We can define default methods in functional interfaces in java 8.
- But every functional interface must have single abstract method in it.
- As we know that default methods should have a implementation as they are not abstract methods.
- Lets see an example program on defining functional interface with default method.
#1: Java example program to create functional interface with default method.
- package com.instanceofjava.java8;
- /**
- * @author www.Instanceofjava.com
- * @category interview programming questions
- *
- * Description: java 8 functional interfaces
- *
- */
- @FunctionalInterface
- public interface FunctionalInterfaceExample {
- void show();
- //default method
- default void message() {
- System.out.println("hello this is default method in functional interface");
- }
- }
#2: Java Example program on how to implement functional interface abstract method and use default method.
- Can we define multiple abstract methods in functional interface ?
- Functional interface with multiple abstract methods in java 8
- Can we define multiple default method inside a functional interface.
- Yes, We can define multiple default methods inside a functional interface
No comments