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

support for importing constants

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 5.0
    • specification
    • generic
    • generic



      Name: gh8910 Date: 02/18/2002



      Many classes and interfaces defines constants as static final values
      such as RED, BLUE, GREEN, etc.

      Programmers often want to have easy access to these constants so
      they can name then as simply RED, BLUE, etc.

      At the moment there is no direct support for doing this in the
      Java language. Unfortunately a rather dangerous idiom has emerged
      to work around this limitation. Programmers define the constants in
      interfaces and then those classes that want easy access to the
      constants say that they implement the interface. This pulls the
      constants into scope.

      Umfortunately this idiom doesn't simply affect the implementation
      of the class. It also affects its API. So for implementation
      convenience programmers are tempetd to add implemementation features
      into their class API.

      It seems better to solve this at the Java langaueg level by adding
      an explicit mechanism to import statics from a class or interface.

      This might take the general form:
          import static x.y.Z.*;

      which would mean import all static constants from the class x.y.Z.




      ======================================================================

            Unassigned Unassigned
            ghamiltosunw Graham Hamilton (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: