title: GroupingBy using Java 8 streams
body: <p>I am working with <code>Java 8 Streams</code> I have a class  like below:</p>
  
  <pre><code>public class ShareDao {
      private String senderId;
      private String receiverId;
  
      public String getSenderId() {
          return senderId;
      }
  
      public String sharingMode(){
          return this.receiverId != null &amp;&amp; !this.receiverId.trim().isEmpty() ? "incoming" : "outgoing";
      }
  }
  </code></pre>
  
  <p>Now what I am trying to do is, I want to: </p>
  
  <ol>
  <li>Filter out the records where senderId is invalid (using a Map&lt;> lookup)</li>
  <li>Group the collection by the senderId and then further group them by the shareMode.</li>
  </ol>
  
  <p>Below is my code:</p>
  
  <pre><code>Map&lt;String, Map&lt;String, List&lt;ShareDao&gt;&gt;&gt; p = records.stream()
              .filter(shared -&gt; userMap.containsKey(shared.getSenderId()))
              .collect(Collectors.groupingBy(ShareDao::getSenderId), Collectors.groupingBy(ShareDao::sharingMode, Function.identity()));
  </code></pre>
  
  <p>It throws me the error:</p>
  
  <blockquote>
    <p>Error:(105, 90) java: no suitable method found for groupingBy(Share[...]gMode,java.util.function.Function)
        method java.util.stream.Collectors.groupingBy(java.util.function.Function) is not applicable
          (cannot infer type-variable(s) T,K
            (actual and formal argument lists differ in length))
        method java.util.stream.Collectors.groupingBy(java.util.function.Function,java.util.stream.Collector) is not applicable
          (no instance(s) of type variable(s) T exist so that java.util.function.Function conforms to java.util.stream.Collector)
        method java.util.stream.Collectors.groupingBy(java.util.function.Function,java.util.function.Supplier,java.util.stream.Collector) is not applicable
          (cannot infer type-variable(s) T,K,D,A,M
            (actual and formal argument lists differ in length))</p>
  </blockquote>
  
  <p>While <code>Intellij Idea</code> raises the error</p>
  
  <p><code>Non-Static method cannot be referenced from static context</code></p>