Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8285935

Spurious lint warning for static method accessed through instance qualifier

    XMLWordPrintable

Details

    • b10

    Description

      Quoting from:
      https://mail.openjdk.java.net/pipermail/compiler-dev/2022-April/019517.html


      public class Demo {
           public static void main(String[] args) {
               var obj = new Object() {
                   static void foo() {
                       System.out.println("Static method of anonymous class");
                   }
               };
               obj.foo(); // Cannot replace instance qualifier with class reference
           }
      }

      With -Xlint:static, javac reports the following warning:

      Demo.java:8: warning: [static] static method should be qualified by
      type name, <anonymous Demo$1>, instead of by an expression
               obj.foo(); // Cannot replace instance qualifier with class reference
                  ^
      1 warning

      Attachments

        Issue Links

          Activity

            People

              vromero Vicente Arturo Romero Zaldivar
              mcimadamore Maurizio Cimadamore
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: