JDK-8061414 : Special syntax for core interfaces
  • Type: Enhancement
  • Component: specification
  • Sub-Component: language
  • Priority: P4
  • Status: Closed
  • Resolution: Other
  • Submitted: 2003-06-12
  • Updated: 2014-10-17
  • Resolved: 2014-10-17
Related Reports
Duplicate :  
Duplicate :  
Duplicate :  
Relates :  
Relates :  
Relates :  
Description
Name: rmT116609			Date: 06/12/2003


A DESCRIPTION OF THE REQUEST :
It would be really nice to provide special syntax for methods of certain core interfaces:

1) Variable x declared to be an instance of a class implementing java.util.List,
     x[i] could be compiled as x.get(i)
  and
     x[i] = y could compiled as x.set(i, y)

2) Variable x declared to be an instance of a class implementing java.util.Map,
      x{k} could be compiled as x.get(k)
    and
      x{k} = y could be compiled as x.put(k, y)

3) For x and y that are instances of classes implementing an interface (yet to be specified, maybe java.lang.Number) that defines arithmetic operations as add, subtract, multiply, lessThan etc.

    x + y is compiled as x.add(y)
    x - y is compiled as x.subtract(y)
    x * y is compiled as x.multiply(y)
    ...
    x < y is compiled as x.lessThan(y)

etc.

JUSTIFICATION :
These are patterns that appear in code again and again, so it's worth providing syntax for making code more concise and make the intention of the code clearer.
(Review ID: 187748) 
======================================================================

Comments
The 'specification' component of the Java Bug System is for reporting technical errors and ambiguities in the text of The Java Language Specification and The JVM Specification. It is not the venue to propose new features in the Java language or JVM. Ongoing feature development is carried out in OpenJDK (http://openjdk.java.net/jeps/); corresponding enhancements to The Java Language Specification and The JVM Specification are managed through the Java Community Process (http://jcp.org/).
17-10-2014

EVALUATION The master RFE for compiler-defined operator overloading.
17-11-2006