DEV Community

J Fowler
J Fowler

Posted on

2

Interface v.s. Functional Interface

For the Java crowd, here's one that some like to use.

Explain the difference between an interface and a functional interface.

Ok let's start with what an interface is.

An interface defines a set of methods required by an implementing class. Consider it a blueprint for a class.

An interface may inherit from multiple interfaces. It may contain abstract methods, constants, static methods and default methods.

a class may implement multiple interfaces.

Ok, now what is a functional interface?

Functional interface can also be called a single abstraction interface.

A functional interface can have only one abstract method. This is the key difference to an interface.

However, a functional interface can have default methods and static methods just like a plain interface.

So, what is the point of a functional interface. The literature suggests that functional interfaces are designed to facilitate the use of lambda expressions where one may want to pass a function as an argument or return one as a result. It is said this makes code more expressive.

So there you have it.

Heroku

Simplify your DevOps and maximize your time.

Since 2007, Heroku has been the go-to platform for developers as it monitors uptime, performance, and infrastructure concerns, allowing you to focus on writing code.

Learn More

Top comments (1)

Collapse
 
prateek_sharma_29a940867d profile image
Prateek Sharma

Thank you for this post :) . It really increased my knowledge about the key difference about them and also about where to use them.

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs