Purely Immutable Design

Dealing with full immutability takes a bit of getting used to. Changing things feels natural, and it’s easy because we’re used to that way of programming in Java. It’s hard to think of ways to total the work years without changing anything, but it’s possible.

We can ask everyone in the room to form a chain while remaining in their seats. Instruct everyone to receive a number from the person on their left, add their own work years to that number, and pass the combined total to the person to their right. I can then provide my own work years to the first person in the room who’s eagerly waiting on me.

In this approach no one ever changes anything. Each person holds the total of work years up to them in the chain. The total ...

Get Programming Concurrency on the JVM now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.