

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to create our own/custom functional interface in Java?
The functional interface is a simple interface with only one abstract method. A lambda expression can be used through a functional interface in Java 8. We can declare our own/custom functional interface by defining the Single Abstract Method (SAM) in an interface.
Syntax
interface CustomInterface { // abtstact method }
Example
@FunctionalInterface interface CustomFunctionalInterface { void display(); } public class FunctionInterfaceLambdaTest { public static void main(String args[]) { // Using Anonymous inner class CustomFunctionalInterface test1 = new CustomFunctionalInterface() { public void display() { System.out.println("Display using Anonymous inner class"); } }; test1.display(); // Using Lambda Expression CustomFunctionalInterface test2 = () -> { // lambda expression System.out.println("Display using Lambda Expression"); }; test2.display(); } }
Output
Display using Anonymous inner class Display using Lambda Expression
- Related Questions & Answers
- How to create our own Listener interface in android?
- How can we create our own choice MySQL database?
- What is Functional Interface in Java 8?
- What is a functional interface in Java?
- What is the generic functional interface in Java?
- Does C++ compiler create default constructor when we write our own?
- How to create your own helper class in Java?
- What are the rules for a functional interface in Java?
- When should we write our own assignment operator in C++?
- Is it mandatory to mark a functional interface with @FunctionalInterface annotation in Java?
- Making your own custom filter tags in Django
- How to create a custom unchecked exception in Java?
- When should we write our own assignment operator in C++ programming?
- How to create custom color maps in Java using OpenCV?
- Java Program to create custom DateTime formatter
Advertisements