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

Explicit import needed to call static method

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Cannot Reproduce
    • 1.0-JSR-2
    • 1.0-JSR-3
    • None
    • None
    • 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

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

            Dates

              Created:
              Updated:
              Resolved: