O'Reilly logo

Scala Puzzlers by Nermin Šerifovic, Andrew Phillips

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Puzzler 27

A Case of Strings

One of Scala's strengths is its interoperability with Java, which allows you to reuse Java libraries and tools without performance penalties. From Scala you can access and extend Java classes, call Java methods, etc.

Unfortunately, Java methods often return null, usually to indicate that no data is available. Although this is a common Java idiom, the ambiguous nature of null causes problems. It is frequently unclear whether the return value of null represents uninitialized, non-existent, or empty values. Besides, it might not be obvious to the caller of a method that null is a possible return value, and as a result, they may forget to explicitly check for null. This causes an astounding number of bugs.

The following ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required