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

JShell : Static import with a locally-defined class gives an error

XMLWordPrintable

    • x86_64
    • windows_10

      A DESCRIPTION OF THE PROBLEM :
      Doing a static import with a locally-defined class gives an error

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      * launch jshell
      * enter the following class definition: class Test { static int ME = 0; }
      * attempt to do a static import of the field Test.ME
      ** with a wildcard: import static Test.*;
      ** with an exact import: import static Test.ME;


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The imports succeed, and ME is directly accessible
      ACTUAL -
      jshell> import static Test.*;
      | Error:
      | cannot find symbol
      | symbol: class Test
      | import static Test.*;
      | ^--^


      jshell> import static Test.ME;
      | Error:
      | cannot find symbol
      | symbol: class Test
      | import static Test.ME;
      | ^--^
      | Error:
      | static import only from classes and interfaces
      | import static Test.ME;
      | ^--------------------^

      CUSTOMER SUBMITTED WORKAROUND :
      declare the field "globally", or use the fully-qualified name of the field (i.e. Test.ME)


            pmangal Priyanka Mangal (Inactive)
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: