The Wild Places

from when our fingertips touch a dewdrop for the first time, or when we breathe the air exhaled from a glacier, or we watch a fern unfurl, delicate whorl upon delicate whorl — We need to hunger in…

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




Java Optional Evolution

Quite long ago around the year 2014 Java 8 was released bringing the new standard to the Java ecosystem. One of the features included in this release was an Optional. Simple yet very useful class for handling nullable objects and values.

Quick time skip to year 2023 and Optional, consists of approx. 500 lines of code and 20 methods with a public access level (including hashCode, equals, toString, and Javadocs) with various possibilities and is widely used throughout the Java ecosystem. But how it was changing through the time, what was added and what deleted ? Answering this question is the main topic of today’s article.

The NullPointerException is one of the most common if not the most common runtime exceptions. It tends to appear in the most unexpected and unwanted places of our code base causing a great deal of trouble to us and our customers.

In Java until the Java 8 release, the only way to deal with them was to use “if ladder”, responsible for checking if the object is not null, which could make our code look like the following sample.

As you can see this code is fairly complex and long. We have to make each non-null check explicitly and in a separate statement so we ended up with a lot of boilerplate. This issue…

Add a comment

Related posts:

Top 3 Most Physically Demanding Sports

This is a tough question to answer as there are so many factors. Therefore, we need to establish what we class as physically demanding. We need to consider the different components of fitness, such…

Expectations of a 21st Century Employee

Organizations around the world are coming to the realization that employees today have a fundamentally different set of expectations than previous generations of workers. There’s no singular reason…

The 5 Lessons I Learned in 2018

My favorite book I have ever read is Man’s Search for Meaning by Viktor Frankl. One of Dr. Frankl’s lessons that still resonates with me to this day is his comparison of two elderly men. Details…