As per the Documentation, Method Reference is absolutely not a static call. It works on both static and non- static methods. When we define our own non-static method in a given class and try to use it using Method Reference then the compile-time-error "cannot make static reference to non static method" is NOT seen in case of Function but only seen in case of Supplier, Consumer and Predicate. Why is that so?
class Demo{
private Function<Student, Integer> p= Student::getGradeLevel; // fine
private Supplier<Integer> s = Student::supply; // compile-time error
private Predicate<Integer> p1= Student::check; //compile-time error
private Consumer<Integer> c= Student::consume; / compile-time error
private Function<String, String> f1 = String::toUpperCase; //fine
}
class Student{
public int getGradeLevel() {
return gradeLevel;
}
public boolean check(int i) {
return true;
}
public int supply() {
return 1;
}
public void consume(int i) {
System.out.println(i);
}
}