JDK-4093687 : Extension of 'Interface' definition to include class (static) methods.
  • Type: Enhancement
  • Component: specification
  • Sub-Component: language
  • Affected Version:
    1.1.4,1.1.5,1.2.2,1.3.0,1.4.0,1.4.1,1.4.2,6,7 1.1.4,1.1.5,1.2.2,1.3.0,1.4.0,1.4.1,1.4.2,6,7
  • Priority: P4
  • Status: Closed
  • Resolution: Won't Fix
  • OS:
    generic,linux,windows_95,windows_98,windows_2000,windows_xp generic,linux,windows_95,windows_98,windows_2000,windows_xp
  • CPU: generic,x86
  • Submitted: 1997-11-18
  • Updated: 2011-10-31
  • Resolved: 2011-10-31
Related Reports
Duplicate :  
Duplicate :  
Duplicate :  
Duplicate :  
Duplicate :  
Duplicate :  
Duplicate :  
Duplicate :  
Name: rm29839			Date: 11/18/97

Please extend the definition of an 'Interface'
to include class (static) methods.

Currently, attempting to expose class methods 
via an interface generates a compiler error, e.g.

MyInterface.java:2: Interface methods can't be 
native, static, synchronized, final, private, 
or protected : void classMethod()
    public static void classMethod ();

This limitation forces one to create two classes
and two interfaces (which in turn creates other
difficulties), instead of one of each, in order
to publish class methods e.g. 'Orders' and 'Order'
classes and interfaces.  Visual Basic's lack of 
class methods forces one to do the same thing.

Noting the other exclusions above, I would also
question why interfaces cannot have final or
synchronized methods.
(Review ID: 19893)

EVALUATION Proposals for new features in the Java programming language are no longer being accepted or maintained in the bug database at http://bugs.sun.com/. This also applies to proposals for new features in the Java Virtual Machine (that is, in the abstract JVM, as opposed to a JVM implementation like HotSpot). All proposals for new features should be made through the "JDK Enhancement - Proposal & Roadmap Process" described at http://openjdk.java.net/jeps/1. This specific request to change the Java programming language is related to the work of OpenJDK Project Lambda. It will be considered further by that project, not here. The bug database continues to accept and maintain submissions about technical errors in the design and specification of the Java programming language and the Java Virtual Machine.

EVALUATION This request is being considered for Dolphin. However, we may well decide not to include this in Dolphin. If so, this RFE will be closed.

WORK AROUND Name: rm29839 Date: 11/18/97 ======================================================================

EVALUATION The fact that interfaces cannot impose constraints on class methods is a problem. I don't know if a language change to address this will ever be realistic, but I believe it's a good idea. The other comments (i.e., why an interface method cannot be synchronized or final) show a misunderstanding. These properties are not part of the type of a method, but of its implementation, and interfaces have no business dictating such details. gilad.bracha@eng 1997-11-18