top of page

Functional Interfaces

  • If an interface contains only one abstract method, then it is called as Functional Interface.

  • Functional Interface is used to invoke lambda expressions.

  • Runnable, Callable, and Comparable are predefined functional interfaces.

1. Runnable => run ( )

2. Callable => call ( )

3. Comparable => compareTo ( )


Note: We can also take default and static methods in functional interface. Only one method rule is applicable for only abstract methods means follow SAM [Single Abstract Method] rule.


Why we need functional interface ?

To invoke lambda expression we need functional interface.

To represent our interface as functional interface we will use @FunctionalInterface. Once we Annotate interface with @FunctionalInterface, compiler will verify whether this interface contain only one abstract or not if more then one abstract method found then it gives compile time error.


Let's see some example...


ree

ree

ree

If you don't know about interface changes in java 8 refer my last blog https://www.miit.tech/post/interface-changes-in-java-8





 
 
 

Recent Posts

See All

Comments


MiIT Logo

Company

Contact Us

905-487-4880 

5160 Explorer Dr #34, Mississauga,ON L4W 4T7

929-743-3199

4466 Buttonwood Ln Lilburn, GA 30047

262 Chapman Rd, STE 240 Newark DE 19702

Stay up to date on the latest from MiIT

  • Instagram
  • Facebook
  • http://linkedin.com/company/miittechnologies/about/
  • Whatsapp

© All Content MiIT Technologies Inc.2019 - 2025. All rights reserved.

bottom of page