How to implement List, Set, and Map in null free design?
- by Pyrolistical
Its great when you can return a null/empty object in most cases to avoid nulls, but what about Collection like objects?
In Java, Map returns null if key in get(key) is not found in the map.
The best way I can think of to avoid nulls in this situation is to return an Entry<T> object, which is either the EmptyEntry<T>, or contains the value T.
Sure we avoid the null, but now you can have a class cast exception if you don't check if its an EmptyEntry<T>.
Is there a better way to avoid nulls in Map's get(K)?
And for argument sake, let's say this language don't even have null, so don't say just use nulls.