title: Non-static method cannot be referenced from a static context in java 8 streams
body: <p>I was playing around with examples from <a href="http://www.concretepage.com/java/jdk-8/java-8-unaryoperator-binaryoperator-example" rel="noreferrer">http://www.concretepage.com/java/jdk-8/java-8-unaryoperator-binaryoperator-example</a>.</p>
  
  <p>What I find really confusing is that when I mistakenly put a wrong type into one of generics when forming Collectors, java compiler gives me a very misleading message:</p>
  
  <blockquote>
    <p>Non-static method cannot be referenced from a static context</p>
  </blockquote>
  
  <p>My error has nothing to do with static vs instance context in reality:</p>
  
  <pre><code>Map&lt;String, Map&lt;Integer, Integer&gt;&gt; mapOfStudents = list.stream().collect(Collectors.groupingBy(Student::getClassName,
              Collectors.toMap(Student::getName, Student::getAge)));
  </code></pre>
  
  <p>My mistake is in generic return type. When I correct it and put:</p>
  
  <pre><code>Map&lt;String, Map&lt;String, Integer&gt;&gt; mapOfStudents
  </code></pre>
  
  <p>everything goes back to normal.</p>
  
  <p>Can someone explain the reason behind such a confusing error message? I'm sure the is a good one, but I fail to grasp it.</p>
  
  <p><strong>EDIT:</strong></p>
  
  <pre><code>~$ java -version
  openjdk version "1.8.0_121"
  OpenJDK Runtime Environment (build 1.8.0_121-8u121-b13-0ubuntu1.16.04.2-b13)
  OpenJDK 64-Bit Server VM (build 25.121-b13, mixed mode)
  </code></pre>