DEV Community

Cover image for Java 8 Functional Interface Cheatsheet
Gunnar Gissel
Gunnar Gissel

Posted on • Updated on • Originally published at gunnargissel.com

Java 8 Functional Interface Cheatsheet

O'Reilly has a great in-depth article on the functional interface in Java 8. Here's a quick cheat sheet to keep track of the main types, what they do and common use cases.

Predicate

A Predicate returns true or false. These are used for filters or replacing big chains of if/else logic.

Function

A Function transforms data. These are used for maps, and other transformations. It is important to not mutate the original data that is passed in.

Supplier

A Supplier takes no arguments and returns a value of a known type. Fetching, reading or creating resources to be used by other functions are common use cases. Suppliers get things started.

Consumer

A Consumer accepts a single argument, but does not return any results. Consumers are where mutating functions, things with side-effects, should go. Consumers finish things.

If you like this, visit my blog for more.

Get a monthly email with great tech and tech leadership articles from around the web

Thanks to Rog01 for the great robot photo

Top comments (0)