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

Interfaces to support static declarations


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


      Name: bsC130419 Date: 08/14/2001

      java version "1.4.0-beta"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-beta-b65)
      Java HotSpot(TM) Client VM (build 1.4.0-beta-b65, mixed mode)

      I would like interfaces to support the declaration of static methods.

      I am not sure on how this is supported overall theory of statics, but what I am
      after is a way for interfaces to enforce the implementation of static methods.

      In that way, I can test a class's isAssignableFrom() method to ascertain if a
      specific interface is supported, but my primary objective is to find a way for
      developers implementing a specific interface *know* that they must implement
      the static method, rather than relying on them reading the appropriate

      An example of where this would be useful is where I might have a static
      creation method on a class, thus:

          public static Object createFromString( String definition )
              return object;

        To offer this from multiple classes, I would like this method to be declared in
      an interface:

      public interface Creatable
          public static Object createFromString( String definition );

      This also allows me to determine whether a class supports this static method
      merely by testing whether it implements the interface, but moreover if a
      developer implements the interface but neglects to implement the method, the
      compiler will detect it.

          Class objectClass = Class.forName( "..." );
          if( objectClass.isAssignableFrom( Creatable.class ) )
              // The static method createFromString is
              // available on the objectClass class

      Although the advantages of this over reflection may seem small, the big benefit
      for me is that I can enforce that if a class implements my interface, then it
      *has* to implement my static method
      (Review ID: 129975)


          Issue Links



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


                • Created: