JSR-334 is dedicated to minor improvements in the Java language, which are implemented in JDK 7
In numeric literals, a group of numbers can now be separated by an underscore: public final static int INT_WITH_UNDERSCORES = 100_000;
Added binary literals with prefix 0b: public final static int BINARY_INT = 0b001100;
Now you can use the String type as the switch key: switch ( "one" ) { case "one" : case "two" : System.out.println( "JSR 334" ); }
Now you can not repeat the type definition when creating a generic class object: List < String > foo = new ArrayList <>();
In the catch block, you can list several exception classes: try { throw new NullPointerException(); } catch (ArithmeticException | NullPointerException e) { }
UPD For syntax checking purposes, the least common type of exceptions listed is used: try { throw new NullPointerException(); } catch (NullPointerException | ArithmeticException e) { // // ArithmeticException a = e; // RuntimeException r = e; }
The following resources are added automatically after the execution of the try block that should implement the java.lang.AutoCloseable interface: class Resource implements AutoCloseable { @Override public void close() throws Exception {} }
A try construct with a self-closing resource can be without catch and finally: try (Resource resource = new Resource()) { throw new Exception(); }
Methods and constructors that use a variable number of variable type arguments will now display an unchecked or unsafe operation warning if they are not annotated by SafeVarargs. You can annotate constructors, final and static methods: class Coin<T> { @SafeVarargs public Coin(T ... args){ } @SafeVarargs public final void instanceMethod(T ... args){ } @SafeVarargs public static void staticMethod(K ... args){ } }