Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Can we define default methods in functional interfaces in java 8

  • 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.

  1. package com.instanceofjava.java8;

  2. /**
  3.  * @author www.Instanceofjava.com
  4.  * @category interview programming questions
  5.  * 
  6.  * Description: java 8 functional interfaces
  7.  *
  8.  */
  9. @FunctionalInterface
  10. public interface FunctionalInterfaceExample {
  11.  
  12. void show();
  13.         //default method
  14. default void message() {
  15. System.out.println("hello this is default method in functional interface");
  16. }
  17. }


#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



This post first appeared on Java Tutorial - InstanceOfJava, please read the originial post: here

Share the post

Can we define default methods in functional interfaces in java 8

×

Subscribe to Java Tutorial - Instanceofjava

Get updates delivered right to your inbox!

Thank you for your subscription

×