Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Learning Java Functional Programming

You're reading from   Learning Java Functional Programming Create robust and maintainable Java applications using the functional style of programming

Arrow left icon
Product type Paperback
Published in Oct 2015
Publisher
ISBN-13 9781783558483
Length 296 pages
Edition 1st Edition
Languages
Arrow right icon
Authors (2):
Arrow left icon
Richard M. Reese Richard M. Reese
Author Profile Icon Richard M. Reese
Richard M. Reese
Richard M Reese Richard M Reese
Author Profile Icon Richard M Reese
Richard M Reese
Arrow right icon
View More author details
Toc

Table of Contents (11) Chapters Close

Preface 1. Getting Started with Functional Programming 2. Putting the Function in Functional Programming FREE CHAPTER 3. Function Composition and Fluent Interfaces 4. Streams and the Evaluation of Expressions 5. Recursion Techniques in Java 8 6. Optional and Monads 7. Supporting Design Patterns Using Functional Programming 8. Refactoring, Debugging, and Testing 9. Bringing It All Together Index

Fluent interfaces

Fluent interfaces provide a convenient and easy-to-use technique for expressing solutions to many different types of problems. They are similar to method chaining but are more natural to use. It is a form of function composition where the method invocations are chained together. In this section, we will discuss the difference and similarities between method chaining, method cascading, and fluent interfaces.

Java supported fluent styles before Java 8 though their use was not common. For example, in JavaFX 2 the IntegerProperty class possesses a number of numerical methods that return the NumberBinding instances. These methods are used in a fluent style as shown here:

    IntegerProperty n1 = new SimpleIntegerProperty(5);
    IntegerProperty n2 = new SimpleIntegerProperty(2);
    IntegerProperty n3 = new SimpleIntegerProperty(3);
    NumberBinding sum = n1
           .add(n2)
           .multiply(n3);
    System.out.println(sum.getValue());

A value of 21 is displayed. The use...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at R$50/month. Cancel anytime