FULL PRODUCT VERSION :
java version "1.8.0_45"
Java(TM) SE Runtime Environment (build 1.8.0_45-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 6.1.7601]
A DESCRIPTION OF THE PROBLEM :
When:
- creating a Comparator by using the static method Comparator.comparing
- and a method reference is used as the "keyExtractor" argument
- and the return type of the method reference does not implement Comparable
then javac gives an inappropriate error message saying "non-static method XXX cannot be referenced from a static context". This is not helpful at all. Instead it should ideally give an error message saying "the key type K does not implement Comparable<K>".
Please see "Steps to Reproduce" for further information.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
save the test case to Issue.java
run javac Issue.java
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
A compiler error saying something like:
the key type K does not implement Comparable<K>
ACTUAL -
A long compiler error, at the very end saying:
invalid method reference
non-static method getInputStream() cannot be referenced from a static context
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.util.Comparator;
public class Issue {
Comparator<Process> cmp = Comparator.comparing(Process::getInputStream);
}
---------- END SOURCE ----------
java version "1.8.0_45"
Java(TM) SE Runtime Environment (build 1.8.0_45-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 6.1.7601]
A DESCRIPTION OF THE PROBLEM :
When:
- creating a Comparator by using the static method Comparator.comparing
- and a method reference is used as the "keyExtractor" argument
- and the return type of the method reference does not implement Comparable
then javac gives an inappropriate error message saying "non-static method XXX cannot be referenced from a static context". This is not helpful at all. Instead it should ideally give an error message saying "the key type K does not implement Comparable<K>".
Please see "Steps to Reproduce" for further information.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
save the test case to Issue.java
run javac Issue.java
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
A compiler error saying something like:
the key type K does not implement Comparable<K>
ACTUAL -
A long compiler error, at the very end saying:
invalid method reference
non-static method getInputStream() cannot be referenced from a static context
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.util.Comparator;
public class Issue {
Comparator<Process> cmp = Comparator.comparing(Process::getInputStream);
}
---------- END SOURCE ----------
- duplicates
-
JDK-8068995 Cleanup method reference lookup code
-
- Closed
-