Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Guava team member here.</p> <p>Probably the single biggest disadvantage of <code>null</code> is that it's not obvious what it should mean in any given context: it doesn't have an illustrative name. It's not always obvious that <code>null</code> means "no value for this parameter" -- heck, as a return value, sometimes it means "error", or even "success" (!!), or simply "the correct answer is nothing". <code>Optional</code> is frequently the concept you actually mean when you make a variable nullable, but not always. When it isn't, we recommend that you write your own class, similar to <code>Optional</code> but with a different naming scheme, to make clear what you actually mean.</p> <p>But I would say the biggest advantage of <code>Optional</code> isn't in readability: the advantage is its idiot-proof-ness. It forces you to actively think about the absent case if you want your program to compile at all, since you have to actively unwrap the <code>Optional</code> and address that case. Null makes it disturbingly easy to simply forget things, and though FindBugs helps, I don't think it addresses the issue nearly as well. This is especially relevant when you're returning values that may or may not be "present." You (and others) are far more likely to forget that <code>other.method(a, b)</code> could return a <code>null</code> value than you're likely to forget that <code>a</code> could be <code>null</code> when you're implementing <code>other.method</code>. Returning <code>Optional</code> makes it impossible for callers to forget that case, since they have to unwrap the object themselves.</p> <p>For these reasons, we recommend that you use <code>Optional</code> as a return type for your methods, but not necessarily in your method arguments.</p> <p>(This is totally cribbed, by the way, from the discussion <a href="https://plus.google.com/103410944693236881656/posts/ayfR8F56PGy" rel="noreferrer">here</a>.)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload