Skip to content

An interface with exactly one abstract method is called Functional Interface. @FunctionalInterface annotation is added so that we can mark an interface as functional interface. It is not mandatory to use it, but it’s best practice to use it with functional interfaces to avoid addition of extra methods accidentally. If the interface is annotated wit

Notifications You must be signed in to change notification settings

Shubh2-0/Functional-Interface

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Functional-Interface

An Interface that contains exactly one abstract method is known as functional interface. It can have any number of default, static methods but can contain only one abstract method. It can also declare methods of object class.

Functional Interface is also known as Single Abstract Method Interfaces or SAM Interfaces. It is a new feature in Java, which helps to achieve functional programming approach.

Example

@FunctionalInterface

interface sayable{

void say(String msg);   

}

public class FunctionalInterfaceExample implements sayable{

public void say(String msg){  

    System.out.println(msg);     
}
public static void main(String[] args) {  

    FunctionalInterfaceExample fie = new FunctionalInterfaceExample();  
    
    fie.say("Hello there");  
    
}  

}

Output:

Hello there

About

An interface with exactly one abstract method is called Functional Interface. @FunctionalInterface annotation is added so that we can mark an interface as functional interface. It is not mandatory to use it, but it’s best practice to use it with functional interfaces to avoid addition of extra methods accidentally. If the interface is annotated wit

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages