So I was reading generics and functional interfaces. There were two ways shown - Using Lambdas, Using method references. There were below examples used:
Predicate<String> ref = String::isEmpty;
Java uses the parameter supplied at runtime as the instance on which isEmpty is called. This is allowed because isEmpty() is an instance method in String class and doesn't take any parameter.
My question is, why does it shows compile error when I use the below line of code:
Supplier<Integer> ref2 = Random::nextInt;
After all, nextInt() is an instance method in Random class just like isEmpty() in String class and it doesn't take parameter either.