title: Java 8 Comparator nullsFirst naturalOrder confused
body: <p>this may be a simple question but I would like to understand it clearly...</p>
  
  <p>I have a code like this:</p>
  
  <pre><code>public final class Persona
  {
     private final int id;
     private final String name
     public Persona(final int id,final String name)
     {
         this.id = id;
         this.name = name;
     }
     public int getId(){return id;}    
     public String getName(){return name;}     
     @Override
     public String toString(){return "Persona{" + "id=" + id + ", name=" + name+'}';}    
   }
  </code></pre>
  
  <p>And I am testing this code:</p>
  
  <pre><code>import static java.util.Comparator.*;
  private void nullsFirstTesting()
  {               
      final Comparator&lt;Persona&gt;comparator = comparing(Persona::getName,nullsFirst(naturalOrder()));
      final List&lt;Persona&gt;persons = Arrays.asList(new Persona(1,"Cristian"),new Persona(2,"Guadalupe"),new Persona(3,"Cristina"),new Persona(4,"Chinga"),new Persona(5,null));
      persons
              .stream()
              .sorted(comparator)
              .forEach(System.out::println);                           
  }
  </code></pre>
  
  <p>This shows the following results:</p>
  
  <pre><code>Persona{id=5, name=null}
  Persona{id=4, name=Chinga}
  Persona{id=1, name=Cristian}
  Persona{id=3, name=Cristina}
  Persona{id=2, name=Guadalupe}
  </code></pre>
  
  <p>These results are OK with me but I have a problem understanding.</p>
  
  <p>When I ignore the <code>new Persona(5,null)</code> object and I pass the comparator:</p>
  
  <pre><code>final Comparator&lt;Persona&gt;comparator = comparing(Persona::getName);
  </code></pre>
  
  <p>It works like a charm. My sorting is by <code>natural order of name property</code>. The problem arises when I add the object with <code>name=null</code>, I just thought I would need my comparator like this. </p>
  
  <pre><code>final Comparator&lt;Persona&gt;comparator = comparing(Persona::getName,nullsFirst());
  </code></pre>
  
  <p>My thought was <strong>erroneous</strong>: "OK, when name is non-null, they are sorted in <code>natural order of name</code>, just like the previous comparator, and if they are <code>null</code> they will be first <strong>but my non-null names will still be sorted in natural order</strong>".</p>
  
  <p>But the right code is this:</p>
  
  <pre><code>final Comparator&lt;Persona&gt;comparator = comparing(Persona::getName,nullsFirst(naturalOrder()));
  </code></pre>
  
  <p>I don't understand the parameter to <code>nullsFirst</code>. I just thought the <code>natural order of name</code> would explicitly [default] even handle <code>null</code> values.</p>
  
  <p>But the docs say:</p>
  
  <blockquote>
    <p>Returns a null-friendly comparator that considers <code>null</code> to be
    less than non-null. When both are <code>null</code>, they are considered
    equal. If both are non-null, the specified <code>Comparator</code> is used
    to determine the order. If the specified comparator is <code>null</code>,
    then the returned comparator considers all non-null values to be equal.</p>
  </blockquote>
  
  <p>This line: "If both are non-null, the specified <code>Comparator</code> is used to determine the order."</p>
  
  <p>I am confused when and how the natural order should be explicitly set or when they are inferred.</p>