-
Enhancement
-
Resolution: Other
-
P4
-
None
-
None
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)
======================================================================
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)
======================================================================
- duplicates
-
JDK-8013058 Make BigDecimal a Primitive Data Type
- Closed
-
JDK-5099780 Add [], -, +, *, / operators to core classes as appropriate
- Closed
-
JDK-6407464 BigInteger should support Autoboxing.
- Closed
- relates to
-
JDK-6176774 arrays should implement Iterable
- Closed
-
JDK-6237556 Addition of Map initialising syntax
- Closed
-
JDK-8061413 Add extensible arrays and dictionaries to the syntax
- Closed
(1 relates to)