title: Comparable class with a List<String> field
body: <p>I have a simple class which stores an integer and a list of Strings.</p>
  
  <p>As I want to use this class in a <code>TreeSet&lt;&gt;</code>, the one must be <code>Comparable</code>.
  But when trying to use the Java 8 <code>Comparator</code> class, I cannot compare my inner list.
  I have the following error: </p>
  
  <blockquote>
    <p>Bad return type in method reference: cannot convert java.util.List to U</p>
  </blockquote>
  
  <p>I think there is a very simple way to do that but I could not find it out.</p>
  
  <p>How to do that?</p>
  
  <pre><code>public class MyClass implements Comparable&lt;MyClass&gt; {
  
      private final int          someInt;
      private final List&lt;String&gt; someStrings;
  
      public MyClass (List&lt;String&gt; someStrings, int someInt) {
          this.someInt = someInt;
          this.someStrings = new ArrayList&lt;&gt;(someStrings);
      }
  
      @Override
      public int compareTo(MyClass other) {
          return
                  Comparator.comparing(MyClass::getSomeInt)
                          .thenComparing(MyClass::getSomeStrings) // Error here
                          .compare(this, other);
      }
  
      public int getSomeInt() {
          return someInt;
      }
  
      public List&lt;String&gt; getSomeStrings() {
          return someStrings;
      }
  }
  </code></pre>
  
  <h3>Edit 1</h3>
  
  <p>I just want the String list to be compared in the simplest way (using implicitly <code>String.compareTo()</code>).</p>
  
  <p>Note that I do now want to sort my <code>List&lt;String&gt;</code> but I want it to be <code>Comparable</code> so that <code>MyClass</code> is also comparable and finally, I can insert <code>MyClass</code> instances into a <code>TreeSet&lt;MyClass&gt;</code>.</p>
  
  <p>A also saw in the JavaDoc the following:</p>
  
  <pre><code>java.util.Comparator&lt;T&gt; public Comparator&lt;T&gt;
      thenComparing(@NotNull Comparator&lt;? super T&gt; other)
  </code></pre>
  
  <blockquote>
    <p>For example, to sort a collection of String based on the length and then case-insensitive natural ordering, the comparator can be composed using following code,</p>
  </blockquote>
  
  <pre><code>Comparator&lt;String&gt; cmp = Comparator.comparingInt(String::length)
     .thenComparing(String.CASE_INSENSITIVE_ORDER);
  </code></pre>
  
  <p>It seems to be an clue but I don't know how to apply it to this simple example.</p>
  
  <h3>Edit 2</h3>
  
  <p>Let's say I want my <code>List&lt;String&gt;</code> to be sorted the following way:</p>
  
  <ul>
  <li>First check: <code>List.size()</code> (the shorter is less than the larger one);</li>
  <li>Second check if sizes match: comparing one by one each element of both Lists until finding one where the <code>String.compareTo</code> method returns 1 or -1.</li>
  </ul>
  
  <p><strong>How to do that with lambdas in a my <code>compareTo</code> method?</strong></p>
  
  <h3>Edit 3</h3>
  
  <p>This does not duplicates <a href="https://stackoverflow.com/questions/35761864/java-sort-list-of-lists">this question</a> because I want to know how to build a comparator of a class which contains a <code>List&lt;String&gt;</code> with Java 8 chaining <code>Comparable</code> calls.</p>