Java 7 is just around the corner. Sadly it does not contain the highly anticipated closures/lambda expressions, but instead it includes a set of small language changes developed under the codename “Project Coin”.

In this post I will explore the basic language changes.

Strings in switch

Yes, finally you can switch on string constants in switch statements!


Binary Literals and Underscores in Numeric Literals

If you work with computer graphics, signal processing or integrate with old native C libraries, you often have to perform bit-manipulations and bit-masking etc. For some strange reason Java only supported decimal, octal and hexadecimal literals. Java Coin adds support for binary literals with the 0b prefix, and now it is legal to use underscores inside all numeric literals to make them easier to read.

 Type Inference for Constructing Instances of Generic Types

This feature is going to remove a lot the verbosity of generic types. Take for example this example of a Map of a List of Strings:

The first method demonstrates the old way of creating generified collections.

The second method demonstrates how you can save a lot of typing by using the diamond operator <> and let the compiler infer the types from the left hand side.

Multi-Catch Exceptions

If you want to perform the same exception handling for a set of Exception types you can now catch them in a single catch statement by separating the types with a pipe character

Automatic Resource Management

The final part of Project Coin is support for automatic resource management, which I will explore in a separate blog post.