4 ms·
FWIW, I use Null Objects to eliminate null checks. Makes recursion (tree climbing) more concise, legible. Bonus: Java's HotSpot magick will NOP (most?) methods
by specialist 1y ago
FWIW, I use Null Objects to eliminate null checks. Makes recursion (tree climbing) more concise, legible.
Bonus: Java's HotSpot magick will NOP (most?) methods of Null Objects, making this a zero cost abstraction.
I should probably write a concrete example for a blog or something.
TLDR: For every base class such as TreeNode, create a NullTreeNode that does nothing, then replace all uses of null with NullTreeNode. Voilá, no more null checks or NPEs.