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

Constants defined in an interface not visible to implementing subclass in a static context

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Critical
    • Resolution: Fixed
    • None
    • 2.0.2, 2.1.0-beta-1
    • None
    • None

    Description

      The following code fails to compile:

      public interface DateTimeFormatConstants {
          static final SimpleDateFormat AM_PM_TIME_FORMAT = new SimpleDateFormat("h:mma")
      
          static final SimpleDateFormat MILITARY_TIME_FORMAT = new SimpleDateFormat("HH:mm")
      }
      
      class DateTimeUtils implements DateTimeFormatConstants {
          static String convertMilitaryTimeToAmPm(String militaryTime) {
              Date date = MILITARY_TIME_FORMAT.parse(militaryTime)
              return AM_PM_TIME_FORMAT.format(date).toLowerCase()
          }
      }
      

      The error message is:

      You attempted to reference a variable in the binding or an instance variable from a static context.
      You misspelled a classname or statically imported field. Please check the spelling.
      You attempted to use a method 'AM_PM_TIME_FORMAT' but left out brackets in a place not allowed by the grammar.
       @ line 13, column 16.
                 return AM_PM_TIME_FORMAT.format(date).toLowerCase()
                        ^
      

      Attachments

        Activity

          People

            paulk Paul King
            behrangsa Behrang Saeedzadeh
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: