---
title: "Java 7 新语言特性(JSR 334: Small Enhancements)"
author: "mysh"
date: "2011-08-24T13:51:01Z"
tags: []
categories: ["编程语言"]
slug: "java-7-jsr-334-small-enhancements"
draft: false
lastmod: "2012-09-10T10:33:16Z"
id: 1156795
url: "https://mysh.iteye.com/blog/1156795"
---

JDK7有不少新东东, 语言特性里有一些更新, 虽然不如 JDK1.5 的泛型/可变参数/for-each循环那么激动人心, 但在平时开发中还是有很大帮助. 个人感觉 try 语句的新特性最有用. 参考: [JSR-334](http://jcp.org/en/jsr/detail?id=334)

写篇文章记录一下.

```
public class CommonTest {

	public static void main(String[] args) {

		List< String> list = ["item"];
		String item = list[0];
		Set< String > set = {"item"};
		Map< String,Integer > map = {"key" : 1};
		int value = map["key"];

		// try-with-resources statement
		try (InputStream in = System.in; OutputStream out = System.out) {

			// Binary integral literals and underscores in numeric literals
			int a = 32_242;
			int b = 0B011_101;
			int c = 023_273;
			int d = 0x23_2c_ab;

			// Improved Type Inference for Generic Instance Creation (diamond)
			List<String> aa = new ArrayList<>();

			// Strings in switch
			String str = "str";
			switch (str) {

			}

			// Multi-catch and more precise rethrow
		} catch (IllegalArgumentException | IndexOutOfBoundsException e) {
		} catch (IOException e) {
		}

	}

	// Simplified Varargs Method Invocation
	@SafeVarargs
	public static  void f(List... t) {

	}

}
```