Get the latest tech news

Omittable – Solving the Ambiguity of Null


Null values in Java are used to present both the absence of a value and the default value of a reference type variable. To design robust APIs, it is necessary to unpack this semantic ambiguity. Omittable is a library solution to this problem.

Our intention was to provide a limited mechanism for library method return types where there needed to be a clear way to represent "no result", and using null for such was overwhelmingly likely to cause errors. Effectively, Optional is a library solution to a language problem: Since the type system does not carry nullability information, it is easy to forget null checks or introduce accidental breaking changes. Incidentally, the lack of special-casing of nulls is also what enables omittable to satisfy all three monad laws.^monad-laws The proof is left as an exercise to the reader.

Get the Android app

Or read this on Hacker News

Read more on:

Photo of null

null

Photo of ambiguity

ambiguity

Related news:

News photo

Some bits on malloc(0) in C being allowed to return NULL

News photo

A farewell to Ada with null (1992)

News photo

Life isn't easy if your last name is 'Null' as it still breaks database entries the world over