|
Duplicate :
|
|
|
Duplicate :
|
|
|
Duplicate :
|
|
|
Duplicate :
|
|
|
Duplicate :
|
|
|
Relates :
|
FULL PRODUCT VERSION :
java version "1.8.0_31"
Java(TM) SE Runtime Environment (build 1.8.0_31-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.31-b07, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Linux jacek 3.2.0-4-amd64 #1 SMP Debian 3.2.63-2+deb7u2 x86_64 GNU/Linux
A DESCRIPTION OF THE PROBLEM :
Invalid method reference thrown by javac when making a reference to a method on an upper bounded wildcard generic type.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Create a file named Sample.java containing the attached source code for class Sample
2. Compile: javac Sample.java
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
File compiles OK.
ACTUAL -
Compilation error occurs
ERROR MESSAGES/STACK TRACES THAT OCCUR :
Sample.java:8: error: invalid method reference
Stream<Runnable> r = s.map(o -> o::work);
^
cannot find symbol
symbol: method work()
location: bound of type variable CAP#1
where CAP#1 is a fresh type-variable:
CAP#1 extends Sample from capture of ? extends Sample
1 error
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.util.stream.Stream;
public class Sample {
void work() { }
void process(Stream<? extends Sample> s) {
Stream<Runnable> r = s.map(o -> o::work);
}
}
---------- END SOURCE ----------
|