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

Class interface support to have interface definition of the static methods

    Details

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

      Description

      Name: rmT116609 Date: 05/12/2004


      A DESCRIPTION OF THE REQUEST :
      Class interface support

      Java Developers right developers invariably face a problem of not able get benefit interfacing the classes that have to define static methods for access or can't even enforce classes to have interface definition of the static methods. Interestingly they have to define an interface for non-static part and an abstract class to enforce static part to the subclasses.

      Example:

      public interface NonStaticPartOfASingleton {
      // non-static methods
      }


      public abstract class AbstractSingleton implements NonStaticPartOfASingleton {
          private static NonStaticPartOfASingleton instance;
          private AbstractSingleton () {
          }
          public static NonStaticPartOfASingleton getInstance() {
              if(instance == null) {
       synchronized {
                           createInstance();
      }
              }
              return instance;
          }
           
          private static void createInstance() {
      return null;
          }
      }

      public class Singleton extends AbstractSingleton {
      // implemetaion
             private static void createInstance() {
      return new Singleton()
              }
      }


      Now comes the tricky part; what if I need to extend the behavior of another class? I’ll end up making a “Adapter” and a “Decorator” to “NonStaticPartOfASingleton” interface. I know after having Class Interface we’ll still have to do this sometimes but key thing is we can avoid 50% of the time.

      Example if we has class interface:
      public interface NonStaticPartOfASingleton {
      // non-static methods
      }

      public classinterface SingletonClass {
           public static NonStaticPartOfASingleton getInstance();
      }

      public class Singleton implements NonStaticPartOfASingleton, SingletonClass {
      // implemetaion
             private static void createInstance() {
      return new Singleton()
              }
      }

      Now you can extend any other if need be.

      This will get us in the new era of;Class Level; inheritance.


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Expected behavior of classinterface:

      1.Should be able to cast Class Objects to classinterface. SingletonClass singletonClass = (SingletonClass) Singleton.class; (Will help in making “Like class” factories)
      2. Should be able to cast Objects to it’s classinterface.
      3. Should be able to use instanceof operator for classinterface.


      CUSTOMER SUBMITTED WORKAROUND :
      I assume well have to make some changes to the class loading mechanisms and class loaders to, with added key word addition to the compiler's lexical. I hope we may also be able to support “public abstract static void doThisMyChild();” like function.
      (Incident Review ID: 232232)
      ======================================================================

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                abuckley Alex Buckley
                Reporter:
                rmandalasunw Ranjith Mandala (Inactive)
              • Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: