Regression: accessing a private method through a type variable
Remi Forax
forax at univ-mlv.fr
Mon Oct 16 08:27:31 UTC 2023
Hello,
There is a regression in recent versions of javac.
javac 21 allows to access a private method through a type variable, here T::asString.
public class TDotToString {
class Bar() {
private String asString() {
return "bar";
}
}
static <T extends Bar> String foo(List<T> list) {
return list.stream().map(T::asString).collect(Collectors.joining());
}
}
Both IntelliJ and Eclipse emit an error in this case.
And javac 8 emits
TDotToString.java:12: error: invalid method reference
return list.stream().map(T::asString).collect(Collectors.joining());
^
cannot find symbol
symbol: method asString()
location: bound of type variable T
where T is a type-variable:
T extends TDotToString.Bar declared in method <T>foo(List<T>)
1 error
regards,
Rémi
More information about the compiler-dev
mailing list