Challenge 2: Explain the Four List Nullability Forms — Possible Solution ==================================================================== [Post] Client code must check whether the entire list is null BEFORE trying to iterate it at all, AND must check each individual item inside it for null before reading any of that item's fields — this is the form requiring the most defensive checking of the four, since nothing is guaranteed. [Post!] Client code must still check whether the list itself is null before iterating (the list as a whole may be absent), but once past that check, it can safely read fields on every item without a per-item null check, since every element inside a present list is guaranteed to be a real, non-null Post. [Post]! Client code can safely assume the list itself always exists (even if it turns out to be an empty array) and can iterate it without a null-check on the list itself, but still needs to check each individual item for null before reading its fields, since any given slot in that array could still be null. [Post!]! Client code needs no defensive null-checking at all for this field — the list is always present, and every item inside it is always a real, non-null Post — the only thing to account for is the possibility of an empty array (zero items), which is a normal, valid state, not a null one. WHY THIS WORKS AS AN EXPLANATION ----------------------------------- The two "!" positions answer two INDEPENDENT questions: "is the list itself guaranteed to exist?" (the ! immediately after the closing bracket) and "is every item inside the list guaranteed to exist?" (the ! immediately before the closing bracket, attached to the inner type). Client code has to defend against exactly the combination of "no" answers present in a given form — [Post] answers "no" to both questions (defend against both), [Post!]! answers "yes" to both (defend against neither, beyond handling a possibly-empty array), and the two middle forms each answer "yes" to one question and "no" to the other, requiring exactly one of the two defensive checks rather than zero or both.