BT

Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ

Topics

Choose your language

InfoQ Homepage News Project Coin Announces Second Candidate List

Project Coin Announces Second Candidate List

This item in japanese

Bookmarks

Project Coin aims to make small language changes for Java 7 which simplify day to day coding for developers. In a previous InfoQ article we looked at the first "for further consideration" cut that had been made for the project comprising: strings in switch, improved exception handling, Automatic Resource Management, improved type inference for generic instance creation, Elvis and other null-safe operators, and simplified Varargs method invocation. Since then a further five proposals have been added to the list.

1. A combined proposal for better integer literals. This is a composite of three separate proposals. Byte and Short Integer Literal Suffixes submitted by Bruce Chapman adds support for byte and short integer literals by introducing 4 new integer type suffixes 'y' & 'Y' for bytes, 's' & 'S' for shorts. Binary Literals is one of a pair of proposals from Derek Foster which adds a new "0b1" (binary) form to the existing "1" (decimal), "01" (octal) and "0x1" (hexadecimal) forms of specifying numeric literals. Foster has also proposed support for underscores in numbers so that long numeric sequences can be broken up to improve readability - for example long creditCardNumber = 1234_5678_9012_3456L;

2. Language support for JSR 292 (wiki). Proposed by John Rose, this will create source-code syntax for using the new JVM features from JSR 292. These are invokeDynamic instructions, method handle invocation, certain relaxed conversions, and exotic identifiers. This change allows Java to interoperate with new JVM languages that rely on the invokeDynamic instruction. It also reduces the dependency on bytecode manipulation techniques when using javac and the JVM as a platform for developing new programming languages and language runtimes. As such is should be a useful spur for developers looking to develop DSLs on top of the Java language.

3. Indexing access syntax for Lists and Maps. Shams Mahmood Imam's proposal aims to provide a consistent syntax for access elements of Arrays, Lists and Maps, so you could write:
myList[0] instead of myList.get(0) and
myMap["key"] instead of myMap.get("key")

4. Collection Literals. Intended to coexist with indexing access syntax for lists and maps and similar to a second proposal from Imam, Josh Bloch adds support for immutable list, set and map literals with a syntax similar to that of array initialisers. An example from the spec:

"Here is a code fragment to create an immutable map as it would be done today:

    final Map<Integer, String> platonicSolids;
    static {
        solids = new LinkedHashMap<Map<Integer, String>;
        solids.put(4,  "tetrahedron");
        solids.put(6,  "cube");
        solids.put(8,  "octahedron");
        solids.put(12, "dodecahedron");
        solids.put(20, "icosahedron");
        platonicSolids = Collections.immutableMap(solids);
    }

Here’s how it would look with map literals:

    final Map<Integer, String> platonicSolids = { 4 : "tetrahedron", 
      6 : "cube", 8 : "octahedron", 12 : "dodecahedron", 20 : "icosahedron" };"

Bloch's proposal differs from Imam's in that it only produces immutable collections, is somewhat more concise, and should make the compiler's job of optimisation for small collections easier. The trade-off is that you cannot specify the implementation type, making it inherently less flexible.

5. Large arrays (revised). Arrays are currently indexed by an int which is a limitation that developers are starting to reach. James Lowden's proposal allows longs to be used as array indices in place of 32-bit ints. Two variants have been looked at - a language level change which would be ideal but is somewhat invasive and may therefore be beyond the scope of Project Coin, and a library-based change that could act as a temporary solution and take advantage of JVM level changes if and when they get added to the language.

Project Coin received around 70 proposals in total from which this final short list of 11 candidates was drawn up. Of these, 5 or 6 are expected to make it into Java 7 and should be available in the milestone 6 release. Once the final cut is made a JSR will be submitted to formalise the changes into the language.

Rate this Article

Adoption
Style

Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Community comments

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

BT