Functional Interfaces in Java 8

Published: 21 August 2018
on channel: skill enabler
247
1

Functional Interfaces in Java 8 :

what is functional interface?

A functional interface is an interface that contains only one abstract method. They can have only one functionality to exhibit.

Examples : Runnable,Comparable are some of the examples of functional interfaces


Important Points:

1. A functional interface has only one abstract method but it can have multiple default methods.
2. @FunctionalInterface annotation is used to ensure an interface can’t have more than one abstract method. The use of this annotation is optional.
3. The java.util.function package contains many builtin functional interfaces in Java 8.

like : Predicate, BinaryOperator, Function etc


@FunctionalInterface Annotation :

@FunctionalInterface annotation is used to ensure that the functional interface can’t have more than one abstract method.

it is not mandatory to use this annotation.


How to create function Interface:

@FunctionalInterface
interface Square
{
int calculate(int x);
}



java.util.function Package:


Predicate:


public Predicate
{
public boolean test(T t);
}

BinaryOperator:

public interface BinaryOperator
{
public T apply(T x, T y);
}

Function:

public interface Function
{
public R apply(T t);
}


On this page of the site you can watch the video online Functional Interfaces in Java 8 with a duration of hours minute second in good quality, which was uploaded by the user skill enabler 21 August 2018, share the link with friends and acquaintances, this video has already been watched 247 times on youtube and it was liked by 1 viewers. Enjoy your viewing!