JDK-4804452 : RFE to add staticinterfaces to java
  • Type: Enhancement
  • Component: specification
  • Sub-Component: language
  • Affected Version: 1.4.1
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_2000
  • CPU: x86
  • Submitted: 2003-01-16
  • Updated: 2003-01-17
  • Resolved: 2003-01-17
Related Reports
Duplicate :  
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) 
======================================================================

Comments
PUBLIC COMMENTS This makes sense, buut is a duplicate. See bug 4093687.
10-06-2004

EVALUATION This issue keeps coming up. It would be quite sensible to support something like this. Bug 4093687 is the original, and has many duplicates. ###@###.### 2003-01-16
16-01-2003