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

Functional interface with multiple methods in java 8

  • Functional interfaces will contains single abstract method with @FunctionalInterface annotation.
  • Check below two posts for defining functional interface and implementing functional interface method using Lamda in java 8.
  • Java 8 functional interface with example
  • Implement java 8 functional interface using lambda example program
  • Now the question is can we declare or define multiple abstract methods in one functional interface in java 8.
  • No. Functional interface should contain only one abstract method so that Lamda will implement it.
  • Lets see what happens if we define multiple abstract methods inside a functional interface
  • Note: all methods inside any interface by default abstract methods.



  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. //compile time error: Invalid '@FunctionalInterface' annotation; FunctionalInterfaceExample is
  12. not a functional interface
  13.  
  14. void show();
  15. void calculate();
  16. }


  • If we define multiple abstract methods inside a functional interface it will throw a compile time error.
  • Invalid '@FunctionalInterface' annotation; FunctionalInterfaceExample is not a functional interface



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

Share the post

Functional interface with multiple methods in java 8

×

Subscribe to Java Tutorial - Instanceofjava

Get updates delivered right to your inbox!

Thank you for your subscription

×