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

Using Lambda Expressions to Clean Up Resources

ARM was a good step in the right direction, but it’s not very effective—never trust anything with the word management in it, right? Just kidding. Anyone using our class has to figure out that it implements AutoCloseable and remember to use the try-with-resources construct. It’d be great if the API we design could guide the programmers and, with the compiler’s help, point them in the right direction. We can achieve that quite easily with lambda expressions.

Preparing the Class for Resource Cleanup

We’ll design a class, FileWriterEAM, that encapsulates heavy resources that need timely cleanup. In this example we’ll use the FileWriter to represent that resource. Let’s make both the constructor and the ...

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