Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-935

Explicit import needed to call static method

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Cannot Reproduce
    • Affects Version/s: 1.0-JSR-2
    • Fix Version/s: 1.0-JSR-3
    • Component/s: None
    • Labels:
      None
    • Environment:
      WinXP, JDK1.5

      Description

      If I want to call a static method, I have to explicitly import the class and can not use an asterix in import.
      This also happen, if the class with the static method is in the same package.

      Example:

      ===== this does not work =======

      // File: somepackage/ClassWithStaticMethod.groovy

      package somepackage

      class ClassWithStaticMethod {
      static staticMethod() {}
      }

      // File: anotherpackage/ClassCallingStaticMethod.groovy

      package anotherpackage

      import somepackage.*

      class ClassCallingStaticMethod {
      def someMethod()

      { ClassWithStaticMethod.staticMethod() }
      }

      ===== this works =======

      package somepackage

      class ClassWithStaticMethod {
      static staticMethod() {}
      }


      package anotherpackage

      import somepackage.ClassWithStaticMethod

      class ClassCallingStaticMethod {
      def someMethod() { ClassWithStaticMethod.staticMethod() }


      }

        Attachments

          Activity

            People

            • Assignee:
              meling Hein Meling
              Reporter:
              tof Christof Vollrath
            • Votes:
              1 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: