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

RFE to add staticinterfaces to java

    Details

    • Type: Enhancement
    • Status: Closed
    • Priority: P4
    • Resolution: Duplicate
    • Affects Version/s: 1.4.1
    • Fix Version/s: None
    • Component/s: specification
    • Labels:
    • Subcomponent:
    • CPU:
      x86
    • OS:
      windows_2000

      Description



      Name: rmT116609 Date: 01/16/2003


      A DESCRIPTION OF THE PROBLEM :
      A staticinterface is related to a normal interface, but works with static methods instead of normal methods.

      New keywords such as 'staticinterface' and 'has' along with a new operator '@' can be introduced and used as follows:

      staticinterface SomeStaticInterface {
        public SomeStaticInterface();

        SomeStaticInterface(Locale aLocale);

        public static void someMethod();

        static void someOtherMethod();
      }

      As can be seen staticinterfaces can have constructors, this indicates that any type that has this staticinterface has corresponding constructors. staticinterfaces can have the same modifiers as other types. Methods in staticinterfaces are all static and can either be public or non-public. In
      the case of non-public methods, this indicates that anything within the same package that uses a type that has this staticinterface will have access to these methods.

      For a type within the same package that has this staticinterface these methods can have either no scope modifier (friendly) or be public. Outside of the package the implementing method must be public. For methods specified to be public in the staticinterface the implementing methods must also be public. As with interfaces, staticinterfaces may extend other
      staticinterfaces.

      class SomeClass has SomeStaticInterface {
        public SomeClass() {
        }

        SomeClass(Locale aLocale) {
        }

        public static void someMethod() {
        }

        static void someOtherMethod() {
        }
      }

      As can be seen SomeClass has SomeStaticInterface and hence it is required to have all the methods specified in SomeStaticInterface. It is possible that a class has more than 1 staticinterface.

      class SomeSubClass extends SomeClass {
      }

      As static methods are not polymorphic, SomeSubClass would need to implement all the methods from SomeStaticInterface in order to say that it has SomeStaticInterface.

      System.out.println(SomeClass.class has SomeStaticInterface); // displays true
      System.out.println(SomeSubClass.class has SomeStaticInterface); // displays false

      has is similar to instanceof, but works with Classes and staticinterfaces instead. Even if SomeSubClass had implemented all the methods from SomeStaticInterface and even though SomeSubClass extends a class that has
      SomeStaticInterface SomeSubClass.class has SomeStaticInterface would still evaluate to false unless SomeSubClass explicitly says that it has
      SomeStaticInterface.

      SomeStaticInterface someStaticInterface =
      SomeStaticInterface@(SomeClass.class);
      someStaticInterface.someMethod();

      @ is similar to () [casting], but works with staticinterfaces and Classes instead. It should be noted that null couldn't be assigned to someStaticInterface as null is not a staticinterface. It should also be noted
      that the compiler would complain about someStaticInterface.someMethod(); if someStaticInterface hadn't previously been initialized.

      class SomeGenericClass<TypeA has SomeStaticInterface> {
        public static void main(String[] args) {
          TypeA a = new TypeA();
          TypeA.someMethod();
        }
      }

      Using generic code it is possible to specify that the parametric type needs to explicitly state that it has some specified staticinterfaces. The methods from the staticinterfaces may then get used on the parametric type
      as the complier enforces that these methods exist.

      Methods on class such as getStaticInterfaces() and isStaticInterface() would also need to get written for use by reflection.


      (Review ID: 179394)
      ======================================================================

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                gbrachasunw Gilad Bracha (Inactive)
                Reporter:
                rmandalasunw Ranjith Mandala (Inactive)
              • Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: