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

Easy way to use constants in a class without qualifying each use

XMLWordPrintable

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

      Name: bsC130419 Date: 05/17/2001


      This is a feature request.

      When calling Java methods, I find that I very frequently pass constants defined
      within the object whose method is being invoked. Qualifying these constants,
      whether with the class or the instance variable results in much tedious typing,
      and much harder-to-read code.

      It would be nice if one could pass such constants without qualification.

      For example, on a record oriented database API:

          DatabaseFile inputFile=new DatabaseFile("abc.dbf");
          inputFile.read(DatabaseFile.NEXT,DatabaseFile.LOCK);

      would become

          DatabaseFile inputFile=new DatabaseFile("abc.dbf");
          inputFile.read(NEXT,LOCK);

      Identifiers passed as parameters to a method could be implicitly qualified
      by the object in which the method resides.

      I would propose that ambiguous references result in a compiler error,
      and the program should explicitly qualify those, only (e.g. from above,
      inputFile.read(DatabaseFile.NEXT,LOCK) or inputFile.read(NEXT,this.LOCK))

      Another alternative would be for Java to provide an easy way to import all the
      public property and/or method references in a nominated class with something
      similar to the import <package> statement. Again, subsequent ambiguous
      references would be bounced. For example:

          import public properties com.mycompany.mypackage.MyClass;
          import public methods com.mycompany.mypackage.MyClass;
          import public com.mycompany.mypackage.MyClass;

      Ditto for protected??

          import protected properties com.mycompany.mypackage.MyClass;
          import protected methods com.mycompany.mypackage.MyClass;
          import protected com.mycompany.mypackage.MyClass;

      And, add a new optional qualifyer "package" for importing package level
      identifiers?

          import package properties com.mycompany.mypackage.MyClass;
          import package methods com.mycompany.mypackage.MyClass;
          import package com.mycompany.mypackage.MyClass;

      What do you think? An idea you can build on, perhaps?
      (Review ID: 124513)
      ======================================================================

            gbrachasunw Gilad Bracha (Inactive)
            bstrathesunw Bill Strathearn (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: