Skip to Content
Functional Programming in Java
book

Functional Programming in Java

by Venkat Subramaniam
February 2014
Intermediate to advanced
160 pages
4h 59m
English
Pragmatic Bookshelf
Content preview from Functional Programming in Java

Creating Fluent Interfaces Using Lambda Expressions

We’ve been looking at the internals of methods and classes in this chapter. Now let’s shift our focus to see how lambda expressions can help shape a class’s skin or interface. We can use these techniques to structure the API of our classes, to make it more intuitive and fluent for programmers to use.

Starting with a Design

Let’s start with a simple Mailer class and evolve the design of its interface.

designing/fpij/Mailer.java
 
public​ ​class​ Mailer {
 
public​ ​void​ from(​final​ ​String​ address) { ​/*... */​ }
 
public​ ​void​ to(​final​ ​String​ address) { ​/*... */​ }
 
public​ ​void​ subject(​final​ ​String​ line) { ​/*... */​ }
 
public​ ​void​ body(​final​ ​String​ message) { ​ ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Functional Programming in Java

Functional Programming in Java

Pierre-Yves Saumont

Publisher Resources

ISBN: 9781941222690Errata Page