title: Using Java supplier/Function to pass method in static method
body: <p>I have a couple of classes:</p>
  
  <pre><code>public class TextContent {
      private String externalId;
  }
  
  public class ImageContent {
      private String externalImageId;
  }
  
  public static void validateImageInput(List&lt;ImageContent&gt; imageAssets, String requestId) {
      if(CollectionUtils.isEmpty(imageAssets)) {
          throw some Error;
      }
  
      Set&lt;String&gt; uniqueIds = imageAssets.stream().map(ImageContent::externalImageId).collect(Collectors.toSet());
      if(uniqueIds.size() != imageAssets().size()) {
          throw some Error;
      }
  
      //Do some processing
  }
  
  public static void validateTextInput(List&lt;TextContent&gt; textAssets, String requestId) {
      if(CollectionUtils.isEmpty(textAssets)) {
          throw some Error;
      }
  
      Set&lt;String&gt; uniqueIds = textAssets.stream().map(ImageContent::externalId).collect(Collectors.toSet());
      if(uniqueIds.size() != textAssets().size()) {
          throw some Error;
      }
  
      //Do some processing
  }
  </code></pre>
  
  <p>As you can see the validation part is the same for both these classes. And I wanted to try and make this a common method. For that:</p>
  
  <pre><code>public static void validateInput(List&lt;?&gt; assets, String requestId, Supplier&lt;String&gt; mapper) {
      if(CollectionUtils.isEmpty(assets)) {
          throw some error;
      }
  
      Set&lt;String&gt; uniqueIds = assets.stream().map(x -&gt; mapper.get()).collect(Collectors.toSet());
      if(uniqueIds.size() != assets().size()) {
          throw some Error;
      }
  }
  </code></pre>
  
  <p>and then call it with :</p>
  
  <pre><code>public static void validateAllInputs(List&lt;ImageContent&gt; imageAssets, List&lt;TextContent&gt; textAssets, String requestId) {
      validateInput(imageAssets, requestId, ImageContent::externalImageId);
      validateInput(textAssets, requestId, TextContent::externalId);
      doSomeProcessingWithText(textAssets, requestId);
      doSomeProcessingWithImage(imageAssets, requestId);
  }
  </code></pre>
  
  <p>But I get an error saying <code>Non static method cannot be referenced from static context.</code></p>
  
  <p>Edit:
  The other option I tried was using <code>Function</code> , i.e I pass in a <code>&lt;TextContent, String&gt; mapper</code> and in my stream I use <code>.map(x -&gt; mapper.apply(x)</code>. However when I try passing it to the function <code>validateInputs(textAsset, requestId, TextContent::externalId)</code> I get the same error <code>Non static method cannot be referenced from static context.</code> </p>