- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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
Is it mandatory to mark a functional interface with @FunctionalInterface annotation in Java?n
An interface defined with only one abstract method is known as Functional Interface. It's not mandatory to mark the functional interface with @FunctionalInterface annotation, the compiler doesn't throw any error. But it’s good practice to use @FunctionalInterface annotation to avoid the addition of extra methods accidentally. If an interface annotated with @FunctionalInterface annotation and more than one abstract method then it throws a compile-time error.
Syntax
@FunctionalInterface interface interface_name { // only one abstarct method declaration }
Example
@FunctionalInterface interface Shape { void printArea(int x); } public class SquareTest { public static void main (String args[]) { Shape square = (x) -> { // Lambda Expression System.out.println("The area of a square is: "+ x*x); }; square.printArea(7); } }
Output
The area of a square is: 49
- Related Articles
- Is it mandatory to override the default methods of an interface in Java?
- What is a functional interface in Java?
- What is Functional Interface in Java 8?
- What is the generic functional interface in Java?
- What are the rules for a functional interface in Java?
- How to create our own/custom functional interface in Java?\n
- Is it mandatory to register the driver while working with JDBC?
- Is it mandatory to close JDBC connections?
- Is it mandatory to link my Aadhaar with bank account and mobile?
- When to use @ConstructorProperties annotation with Jackson in Java?
- Is it mandatory to use T for type-parameter, while defining Generics classes/methods in Java?
- NavigableMap Interface in Java with Example
- When to use @JsonAutoDetect annotation in Java?
- Can we declare an interface with in another interface in java?
- What is a remote interface in java?

Advertisements