JDK-8061413 : Add extensible arrays and dictionaries to the syntax
  • Type: Enhancement
  • Component: specification
  • Sub-Component: language
  • Priority: P5
  • Status: Closed
  • Resolution: Other
  • Submitted: 2002-02-04
  • Updated: 2015-08-06
  • Resolved: 2014-10-17
Related Reports
Duplicate :  
Relates :  
Relates :  
Relates :  
Description
Name: gm110360			Date: 02/04/2002


FULL PRODUCT VERSION :
java version "1.4.0-rc"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-rc-b91)
Java HotSpot(TM) Client VM (build 1.4.0-rc-b91, mixed mode)


FULL OPERATING SYSTEM VERSION :



A DESCRIPTION OF THE PROBLEM :
A number of modern languages (most recently, Python) support syntax-level creation and modification of certain basic extremely common data types, including strings, extensible arrays, and dictionaries.  Java's facilities here are unnecessarily poor.  Consider the following grotesque but sadly common example:

Vector vec = new Vector();
vec.addElement(new Double(2.3));
vec.addElement(new Double(4.5));
vec.addElement(new Double(3.1));
vec.addElement(new Double(2.6));
double d = ((Double)(vec.elementAt(2))).doubleValue();

...as opposed to an alternative syntax:
double[] vec = new double[0];
vec += 2.3; vec += 4.5; vec += 3.1; vec += 2.6;
double d = vec[2];

...or if the += and + operators would be better suited to array concatenation, even a functional form would be preferred over the current monstrosity:

double[] vec = new double[0];
vec.push(2.3).push(4.5).push(3.1).push(2.6);
double d = vec[2];

Given that Java has no multidimensional arrays, this is a trivially easy thing to add to the semantics of the language.  Just lazily define arrays as fixed-length until they are acted upon with variable-length operators, and then upgrade them to variable-length.

While we're at it, Java's hashtable (and HashMap/HashSet) facility is similarly grotesque, not permitting numbers or string values as keys, and requiring a nasty syntax:

Hashtable h = new Hashtable();
h.put("key1","value1");
h.put("key2","value2");
h.put("key3","value3");

...instead of something like:

Hashtable h =
   << "key1","value1" : "key2","value2", "key3","value3">>;

These objects are so basic to Java that the enormously wordy syntax they rely on is only a hindrance.


This bug can be reproduced always.
(Review ID: 139148) 
======================================================================

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 If we adopt the special syntax for setting and getting Collection elements (e.g. "x[i] could be compiled as x.get(i)" in 4877954), then this request would make sense too.
21-05-2008

EVALUATION Unlikely to change in the foreseeable future. The amount of special purpose sugar (often conflicting) different users request is enormous, and is often suited only to a subset of usages. ###@###.### 2002-02-04
04-02-2002