title: Kotlin sorting nulls last
body: <p>What would be a Kotlin way of sorting list of objects by nullable field with nulls last? </p>
  
  <p>Kotlin object to sort:
  </p>
  
  <pre><code>@JsonInclude(NON_NULL)
  data class SomeObject(
      val nullableField: String?
  )
  </code></pre>
  
  <p>Analogue to below Java code:</p>
  
  <pre class="lang-java prettyprint-override"><code>@Test
  public void name() {
      List&lt;SomeObject&gt; sorted = Stream.of(new SomeObject("bbb"), new SomeObject(null), new SomeObject("aaa"))
              .sorted(Comparator.comparing(SomeObject::getNullableField, Comparator.nullsLast(Comparator.naturalOrder())))
              .collect(toList());
  
      assertEquals("aaa", sorted.get(0).getNullableField());
      assertNull(sorted.get(2).getNullableField());
  }
  
  @Getter
  @AllArgsConstructor
  private static class SomeObject {
      private String nullableField;
  }
  </code></pre>