首页 > 程序开发 > 软件开发 > Java >

java 7 新特性 (类型推断,支持String 的swtich语法)...

2011-12-02

1.更好的2进制文本int mask = 0b101010101010;支持下划线int mask = 0b1010_1010_1010;long big = 9_223_783_036_967_937L;2.支持Strring Switch Statement以前case 支持int 和枚举现在String 也支...

1.更好的2进制文本

int mask = 0b101010101010;

支持下划线

int mask = 0b1010_1010_1010;

long big = 9_223_783_036_967_937L;

2.支持Strring Switch Statement

以前case 支持int 和枚举

现在String 也支持

int monthNameToDays(String s, int year) {

switch(s) {

case "April": case "June":

case "September": case "November":

return 30;

case "January": case "March":

case "May": case "July":

case "August": case "December":

return 31;

3.可推断的数据类型<>

(1)没有泛型

List strList = new ArrayList();

(2)具有泛型

List<String> strList = new ArrayList<String>();

List<Map<String, List<String>> strList =

new ArrayList<Map<String, List<String>>();

(3)java 7支持的类型

List<String> strList = new ArrayList<>();

List<Map<String, List<String>> strList =

new ArrayList<>();

4.Exceptions Galore

try {

...

} catch(ClassNotFoundException cnfe) {

log(cnfe);

throw cnfe;

} catch(InstantiationException ie) {

log(ie);

throw ie;

} catch(NoSuchMethodException nsme) {

log(nsme);

throw nsme;

} catch(InvocationTargetException ite) {

log(ite);

throw ite;

}

Multi-Catch

try {

// Reflective operations calling Class.forName,

// Class.newInstance, Class.getMethod,

// Method.invoke, etc.

} catch(final ClassNotFoundException |

InstantiationException |

NoSuchMethodException |

InvocationTargetException e) {

log(e);

throw e;

}

摘自 rjgcx2的专栏

相关文章
最新文章
热点推荐