- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What is Functional Interface in Java 8?
A functional interface is an interface that has only one abstract method. They are bound to exhibit singular functionality. Runnable, Comparable and Predicate are a few examples of functional interfaces.
@FunctionalInterface Annotation is used to ensure that the functional interface can’t have more than one abstract method. Java 8 onwards, we can assign lambda expressions to functional interface objects.
Let us see how a user defined functional interface works out −
Example
@FunctionalInterface interface Cube { int compute(int x); } public class Example { public static void main(String args[]) { int p = 6; Cube c = r -> r * r * r; // lambda expression which defines the compute method int result = c.compute(p); System.out.println(result); } }
Output
The output is as follows −
216
Advertisements