title: Why does this java 8 stream operation evaluate to Object instead of List<Object> or just List?
body: <p>I'm working with a 3d party library, and they return Collections that lack type specifications  (e.g. <code>public List getFoo();</code>) , and I'm trying to convert their return types and return a list with a proper type. </p>
  
  <p>I have created a simple example that demonstrates the problem. e.g.</p>
  
  <p><em>edit</em> The original question declared l2 as an <code>ArrayList</code> rather than a <code>List</code>, that is corrected now.</p>
  
  <pre><code>import java.util.List;
  import java.util.ArrayList;
  import java.util.stream.Collectors;
  
  public class Foo {
      public static void main(String[] args) {
          ArrayList l = new ArrayList();
          l.add(1);
          l.add(2);
          List&lt;String&gt; l2 = l.stream().map(Object::toString).collect(Collectors.toList());
      }
  }
  </code></pre>
  
  <p>This fails to compile.</p>
  
  <pre><code>$ javac Foo.java
  Foo.java:10: error: incompatible types: Object cannot be converted to List&lt;String&gt;
          List&lt;String&gt; l2 = l.stream().map(Object::toString).collect(Collectors.toList());
                                                                    ^
  1 error
  </code></pre>
  
  <p>If I modify the program slightly so it compiles and I can check the return type of the stream/collect operation. It "works", although I'd have to cast the result.</p>
  
  <p>e.g.</p>
  
  <pre><code>import java.util.ArrayList;
  import java.util.stream.Collectors;
  
  public class Foo {
      public static void main(String[] args) {
          ArrayList l = new ArrayList();
          l.add(1);
          l.add(2);
          Object l2 = l.stream().map(Object::toString).collect(Collectors.toList());
          System.out.println(l2.getClass());
      }
  }
  </code></pre>
  
  <p>Running this shows...</p>
  
  <pre><code>$ javac Foo.java
  Note: Foo.java uses unchecked or unsafe operations.
  Note: Recompile with -Xlint:unchecked for details.
  $ java Foo
  class java.util.ArrayList
  </code></pre>
  
  <p>As expected.</p>
  
  <p>So, Collectors.listCollector() does the right thing at runtime, but is this compile time behavior expected? If so, is there a "proper" way around it?</p>