Regression: accessing a private method through a type variable

Remi Forax forax at
Mon Oct 16 08:27:31 UTC 2023

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) {

Both IntelliJ and Eclipse emit an error in this case.

And javac 8 emits error: invalid method reference
  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


More information about the compiler-dev mailing list