title: Calling stream().reduce() on a list with only one element
body: <p>I am new to functional programming in java, and wonder how I should code to avoid NPE in (for example) this operation:</p>
  
  <pre><code>myList.stream()
        .reduce((prev, curr) -&gt; prev.getTimestamp().isAfter(curr.getTimestamp()) ? prev : curr);
        .get().getTimestamp();
  </code></pre>
  
  <p>My intent here is to find the timestamp of the newest object in the list. Suggestions on how to better collect the last element are very welcome, but my main question here is actually why this works.</p>
  
  <p>The documentation says that the function throws a <code>NullPointerException</code> "if the result of the reduction is null":</p>
  
  <p><a href="http://docs.oracle.com/javase/8/docs/api/java/util/stream/Stream.html#reduce-java.util.function.BinaryOperator-" rel="noreferrer">http://docs.oracle.com/javase/8/docs/api/java/util/stream/Stream.html#reduce-java.util.function.BinaryOperator-</a></p>
  
  <p>That is OK, but what I don't quite understand is why I don't get a <code>NullPointerException</code> when this code is run with a list containing only one element. I expected <code>prev</code> to be null in such a case. I tried debugging, but it just seems to step over the entire lambda expression when there is only one element.</p>