title: Stream Collections Error and understanding
body: <p>I'm trying to read in a CSV using java 8's <code>Stream</code> API and create a matrix from it.</p>
  
  <p>This is mainly to learn <code>Stream</code>s (there are of course other ways to do this without <code>Stream</code>s).</p>
  
  <p>Here is the code:</p>
  
  <pre><code>public class MatrixCreator {
  
      public static Function&lt;String, List&lt;Double&gt;&gt; mapLineToListOfDoubles = (line) -&gt; {
          String [] elements = line.split(",\\s*");
          return Arrays.stream(elements).map((String stringElement) -&gt; Double.parseDouble(stringElement)).collect(Collectors.toList());
      };
  
      //Error from this -- listed below
      public static Collector&lt;List&lt;Double&gt;, List&lt;Double&gt;, List&lt;Double&gt;&gt; listCollector = Collector.of(ArrayList&lt;Double&gt;::new, List&lt;Double&gt;::addAll, (ArrayList&lt;Double&gt; left, List&lt;Double&gt; right) -&gt; {
          left.addAll(right);
          return left;
      });
  
  
      /**
       * Creates a matrix from the specified file.
       * @param filePath Path to CSV, matrix, file
       */
      public static Matrix createMatrix(String filePath) throws IOException {
          FileInputStream fileInputStream = new FileInputStream(filePath);
          BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(fileInputStream));
          List&lt;Double&gt; x = bufferedReader.lines().map(mapLineToListOfDoubles).collect(listCollector);
          return null;  // for the moment.
      }
  }
  </code></pre>
  
  <p>The following error is given:</p>
  
  <pre><code>Error:(26, 96) java: no suitable method found for of(ArrayList&lt;[...]::new,List&lt;Doubl[...]ddAll,(ArrayList[...]ft; })
      method java.util.stream.Collector.&lt;T,R&gt;of(java.util.function.Supplier&lt;R&gt;,java.util.function.BiConsumer&lt;R,T&gt;,java.util.function.BinaryOperator&lt;R&gt;,java.util.stream.Collector.Characteristics...) is not applicable
        (inferred type does not conform to equality constraint(s)
          inferred: java.util.List&lt;java.lang.Double&gt;
          equality constraints(s): java.util.List&lt;java.lang.Double&gt;,java.util.ArrayList&lt;java.lang.Double&gt;)
      method java.util.stream.Collector.&lt;T,A,R&gt;of(java.util.function.Supplier&lt;A&gt;,java.util.function.BiConsumer&lt;A,T&gt;,java.util.function.BinaryOperator&lt;A&gt;,java.util.function.Function&lt;A,R&gt;,java.util.stream.Collector.Characteristics...) is not applicable
        (cannot infer type-variable(s) T,A,R
          (actual and formal argument lists differ in length))
  </code></pre>
  
  <p>Clearly Java cannot determine the method to use, but I cannot determine where to go from here.</p>
  
  <p>I'd appreciate any help regarding the reason for this error.</p>