Posts

Showing posts from February, 2015

Java 8 - Lambda Tutorial

Image
I've been working with Java 8 for a few months now and to be honest I've been pretty impressed so far. There are a number of exciting new features that have changed the language for the better, but lambda expressions, in my opinion stand out.

What is a lambda expression? In simple terms a lambda expression is a piece of code that can be passed to another method as a parameter, and then executed by the receiving method. The ability to parametrise behaviour is not new to Java and is something you've probably done many times with anonymous classes. Lambdas however provide a more elegant means of passing code to another method for execution. To show you the benefits of lambdas we'll first look at how we would have implemented behaviour parametrisation prior to Java 8.

Problem Domain Our problem domain is a simple one. We have a list of bank account objects that we'd like to filter using various criteria. The account object is a simple POJO defined as follows (getters &am…