Tag Archives: anonymous classes

Java Lambda Expression Basics

Java 8 introduced Lambda expressions. Lambda expressions are a shorthand for implementing single method interfaces. By a single method interface, I mean something like the following.

package com.tgenedavis.lambda;

public interface Flower {
	public void bloom();
}

The interface Flower has a single method called bloom(). Before Lambda expressions, we could implement single method interfaces with an anonymous class or with a normal class.

Continue reading Java Lambda Expression Basics

Implementing Runnables the Lambda Way

Java 8 introduced Lambda expressions. We’ve been told they would bring simpler easier-to-read programs. We’ve been told that Lambda expressions create multi-core friendly code. Functional programs created with Lambda expressions have fewer bugs, saving development time and maintenance costs. Rumor has it that the release of Java 8 was the moment when the rise of the oceans began to slow and our planet began to heal; it was the moment when we ended all language wars and secured Java’s image as the last, best hope on Earth.

I’m not saying it’s all true. That’s just what I’ve heard.

To decipher rumor from truth, we need to start with some basics. There is a lot of complex, albeit cool, stuff that the experts can do with Lambda expressions. We’ll start with a basic tutorial on how to use a Lambda expression to implement a Runnable.

Continue reading Implementing Runnables the Lambda Way