title: Extending List<T> in Java 8
body: <p>I often want to map one list into another list. For example if I had a list of people, and I wanted a list of their names, I would like to do:</p>
  
  <p><strong>GOAL</strong> </p>
  
  <pre><code>List&lt;Person&gt; people = ... ;
  
  List&lt;String&gt; names = people.map(x -&gt; x.getName());
  </code></pre>
  
  <p>Something like this is possible with Java 8:</p>
  
  <p><strong>JAVA 8 VERSION</strong></p>
  
  <pre><code>List&lt;String&gt; names = people.stream()
                             .map(x -&gt; x.getName())
                             .collect(Collectors.toList());
  </code></pre>
  
  <p>But this is clearly not as nice. In fact, I think using Guava is cleaner:</p>
  
  <p><strong>GUAVA VERSION</strong></p>
  
  <pre><code>List&lt;String&gt; names = Lists.transform(people, x -&gt; x.getName());
  </code></pre>
  
  <p>However, I do like chaining. So, is my goal possible?</p>
  
  <p>I have heard people say that Java 8 default methods are similar to C# extension methods. With a C# extension method, I could easily add a helper method to <code>IEnumerable&lt;T&gt;</code>:</p>
  
  <pre><code>public static IEnumerable&lt;TRet&gt; Map&lt;T, TRet&gt;(this IEnumerable&lt;T&gt; list, Func&lt;T, TRet&gt; selector)
  {
      return list.Select(selector);
  }
  </code></pre>
  
  <p>However I can't figure out how to use default methods to <em>extend an existing interface</em>.</p>
  
  <p>Also, this is obviously a trivial example. In general, I would like to be able to extend the <code>List&lt;T&gt;</code> and <code>Iterable&lt;T&gt;</code> interfaces to make interacting with the streams api easier.</p>