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

Spurious lint warning for static method accessed through instance qualifier

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Open
    • Priority: P4
    • Resolution: Unresolved
    • Affects Version/s: 19
    • Fix Version/s: 20
    • Component/s: tools
    • Labels:

      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

          Activity

            People

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

              Dates

              Created:
              Updated: