title: Java 8: method reference to a static method in a non-static way
body: <p>I'm studying the new Stream API for the OCP exam and I found something that I don't really understand. Here's my code:</p>
  
  <pre><code>void methodOne() {
      this.compare(1, 2); // This works fine.
      Stream.of(1,2,3)
          .sorted(this::compare); // Compilation error.
  }
  
  static Integer compare(Integer s1, Integer s2) {
      return 0;
  }
  </code></pre>
  
  <p>Here I have a static method called compare and a non-static one called compare. If I call the compare method from the non-static method I get a compiler warning:</p>
  
  <blockquote>
    <p>The method compare(Integer, Integer) from the type TestStream should be accessed in a static way</p>
  </blockquote>
  
  <p>If I instead use a method reference to that same method in my stream, that compiler warning becomes a compiler error with the same message.</p>
  
  <p>I know why I get the warning but I don't get why this warning becomes a compilation error if I use a method reference. I didn't find anything online either. Can someone explain it to me? </p>