#72 Functional Interface New in Java

preview_player
Показать описание
Check out our courses:

Coupon: TELUSKO10 (10% Discount)

Coupon: TELUSKO10 (10% Discount)

Coupon: TELUSKO20 (20% Discount)

For More Queries WhatsApp or Call on : +919008963671

Udemy Courses:

In this lecture, we are discussing functional interface:
#1 what is functional Interface?
--functional interface is an interface with only one abstract method

#2
The properties of a functional interface in Java are as follows:

Single Abstract Method: A functional interface has only one abstract method.
This method is the signature of the interface and defines the behaviour that will be implemented in the lambda expression or with simple class.

Functional Method: The abstract method of a functional interface is called the functional method.
It is the method that provides the functional behaviour of the interface.

@FunctionalInterface Annotation: A functional interface is annotated with the @FunctionalInterface annotation.
This annotation is optional, but it provides a compile-time check that the interface has only one abstract method.

Compatible with Lambda Expressions: A functional interface is compatible with lambda expressions.
A lambda expression is a concise way of implementing the functional method of a functional interface.
(This will discuss in next lecture of lambda expression).

Functional interfaces are a key component of functional programming in Java,
and they are used extensively in the Java 8 Streams API and other Java libraries.

#3 Example
class Main{
public static void main(String []args){
A obj = new B();

//another way to implement functional interface
A obj1 = new A(){
@Override
public void show(){
}
};

}
}

//one way to implement functional interface
class B implements A{
@Override
public void show(){
}
}

//specify it is functional interface
@FunctionalInterface //we use this annotation to specify it is functional interface
interface A{
void show();
//void run(); //this will give error as it is a functional interface you cannot write two abstract method in this
}

More Learning :

Donation:
PayPal Id : navinreddy20
Рекомендации по теме
Комментарии
Автор

00:00 Functional interfaces in Java have only one method.
00:29 Functional Interfaces in Java enable single abstract method implementation
00:57 Functional interfaces must have only one abstract method.
01:23 Functional interfaces cannot be directly instantiated
01:51 Exploring different ways to implement functional interfaces in Java
02:15 Functional interfaces allow defining a method implementation inline in Java.
02:40 Java 8 introduces less verbose coding with Functional Interfaces
03:11 Lambda expressions in Java 8 are used with functional interfaces.

Stranger_SP
Автор

I have doubt ....
But interface name not create object, class name make object, interface only object reference
I mean A obj=new A() not right...
Object banane ke leye class banani padegi

ritusinghthakur
Автор

We already have interface... Then why we are going to functional interface?

v.kowsalyavelmurugan
Автор

A obj1 = new A(){
@Override
public void show(){
System.out.println("Hello");
}
};
obj1.show();

}
}
I am note getting the output, it is showing Type A is already defined..pls help

simizara
Автор

why do they introduce functional interface in java 8 and tell me that one

balapadma-tnun
Автор

"we want errors, right?" 😅 ... well, just in this case.... 😉

pamu
Автор

hELLO SIR, I LOVE UR CLASSES. WOULD BE GREAT IF WE HAD SOME BACKGROUND MUSIC. WOULD BE ENGAGING TO WATCH

arjunthazhatha
Автор

Someone should tell you not to teach Java and write method brackets on new lines. This is not C#.

CvetanSimsic