Modern thinking, it seems, should βtolerateβ zeros, that is, resolve them at all, although some operations are less tolerant and may ultimately throw NPE. See the discussion of zeros on the Lambda Libraries expert group mailing list, specifically this post . After that, there was consensus around option No. 3 (with a notable objection from Doug Lee). So yes, the OP's concern regarding pipelines exploding with NPE is, indeed.
Itβs not for nothing that Tony Hoar mentioned the zeros as βA billion dollar error.β Working with zeros is a real pain. Even with classic collections (excluding lambda or threads) zeros are problematic. Like the fge mentioned in the comment, some collections are null while others are not. With nullable collections, this introduces ambiguity into the API. For example, with Map.get (), a null return indicates either that the key is present and its value is null, or that the key is not in place. Additional work needs to be done to eliminate these cases.
The usual use for null is to indicate the absence of a value. The approach to consider this proposal for Java SE 8 is to introduce a new type java.util.Optional that encapsulates the presence / absence of a value, along with the behavior of providing a default value or throwing an exception or calling a function, etc. if value is missing. Optional used only by the new APIs, but everything else on the system must still put up with the possibility of zeros.
My advice is to avoid actual null references as much as possible. It is difficult to see from the given example how there can be a "zero" otter. But if necessary, OP's suggestions on filtering zero values ββor matching them with a sentinel object (
Stuart Marks Jun 14 '13 at 18:59 2013-06-14 18:59
source share