| I was reading through one of the linked articles of why the author doesn't like using null or static objects: https://www.yegor256.com/2014/05/13/why-null-is-bad.html https://www.yegor256.com/2014/05/05/oop-alternative-to-utili... Apparently he replaces null with null objects or throwing exceptions, and creates objects for every static method. Go figure. Actually, there are a few gems: > The Map interface (no offense to its authors) has a design flaw. > It is a good practice to make your code as fragile as possible, letting it break when necessary. > The method is basically asking the object about its… race. Black objects go right while white objects go left. That’s what this instanceof is doing, and that’s what discrimination is all about. |
That's what Optional was introduced for in Java 8. If you want to be absolutely null-safe, using it makes sense. But if you want to optimise performance, going with the slightly more risky route is still the better choice.