DEV Community

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

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

7

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

AWS Q Developer image

Your AI Code Assistant

Automate your code reviews. Catch bugs before your coworkers. Fix security issues in your code. Built to handle large projects, Amazon Q Developer works alongside you from idea to production code.

Get started free in your IDE

Top comments (0)

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay