java 的新语言,Java 七 新语言特性(JSR 334: Small Enhancements)

Java 7 新语言特性(JSR 334: Small Enhancements)

JDK7有不少新东东, 语言特性里有一些更新, 虽然不如 JDK1.5 的泛型/可变参数/for-each循环那么激动人心, 但在平时开发中还是有很大帮助. 个人感觉 try 语句的新特性最有用. 参考: JSR-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 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) {

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值