did*_*xga 203
这是OpenJDK 7功能页面中的Java 7新功能摘要:
vm JSR 292: Support for dynamically-typed languages (InvokeDynamic)
Strict class-file checking
lang JSR 334: Small language enhancements (Project Coin)
core Upgrade class-loader architecture
Method to close a URLClassLoader
Concurrency and collections updates (jsr166y)
i18n Unicode 6.0
Locale enhancement
Separate user locale and user-interface locale
ionet JSR 203: More new I/O APIs for the Java platform (NIO.2)
NIO.2 filesystem provider for zip/jar archives
SCTP (Stream Control Transmission Protocol)
SDP (Sockets Direct Protocol)
Use the Windows Vista IPv6 stack
TLS 1.2
sec Elliptic-curve cryptography (ECC)
jdbc JDBC 4.1
client XRender pipeline for Java 2D
Create new platform APIs for 6u10 graphics features
Nimbus look-and-feel for Swing
Swing JLayer component
Gervill sound synthesizer [NEW]
web Update the XML stack
mgmt Enhanced MBeans [UPDATED]
这个:
BufferedReader br = new BufferedReader(new FileReader(path));
try {
return br.readLine();
} finally {
br.close();
}
Run Code Online (Sandbox Code Playgroud)
变为:
try (BufferedReader br = new BufferedReader(new FileReader(path)) {
return br.readLine();
}
Run Code Online (Sandbox Code Playgroud)
您可以声明要关闭的多个资源:
try (
InputStream in = new FileInputStream(src);
OutputStream out = new FileOutputStream(dest))
{
// code
}
Run Code Online (Sandbox Code Playgroud)
int one_million = 1_000_000;
Run Code Online (Sandbox Code Playgroud)
String s = ...
switch(s) {
case "quux":
processQuux(s);
// fall-through
case "foo":
case "bar":
processFooOrBar(s);
break;
case "baz":
processBaz(s);
// fall-through
default:
processDefault(s);
break;
}
Run Code Online (Sandbox Code Playgroud)
int binary = 0b1001_1001;
Run Code Online (Sandbox Code Playgroud)
Map<String, List<String>> anagrams = new HashMap<String, List<String>>();
Run Code Online (Sandbox Code Playgroud)
变为:
Map<String, List<String>> anagrams = new HashMap<>();
Run Code Online (Sandbox Code Playgroud)
这个:
} catch (FirstException ex) {
logger.error(ex);
throw ex;
} catch (SecondException ex) {
logger.error(ex);
throw ex;
}
Run Code Online (Sandbox Code Playgroud)
变为:
} catch (FirstException | SecondException ex) {
logger.error(ex);
throw ex;
}
Run Code Online (Sandbox Code Playgroud)
这个:
@SuppressWarnings({"unchecked", "varargs"})
public static void printAll(List<String>... lists){
for(List<String> list : lists){
System.out.println(list);
}
}
Run Code Online (Sandbox Code Playgroud)
变为:
@SafeVarargs
public static void printAll(List<String>... lists){
for(List<String> list : lists){
System.out.println(list);
}
}
Run Code Online (Sandbox Code Playgroud)
小智 13
使用JLayer类装饰组件:
JLayer类是Swing组件的灵活且强大的装饰器.Java SE 7中的JLayer类在精神上与java.net中的JxLayer项目项目类似.JLayer类最初基于JXLayer项目,但其API分别发展.
switch中的字符串声明:
在JDK 7中,我们可以在switch语句的表达式中使用String对象.Java编译器通常使用String对象生成比使用链式if-then-else语句更高效的字节码.
通用实例的类型推断:
只要编译器可以从上下文中推断出类型参数,我们就可以用一组空的类型参数(<>)替换调用泛型类的构造函数所需的类型参数.这对尖括号被非正式地称为钻石.Java SE 7支持通用实例创建的有限类型推断; 如果构造函数的参数化类型在上下文中很明显,则只能使用类型推断.例如,以下示例不编译:
List<String> l = new ArrayList<>();
l.add("A");
l.addAll(new ArrayList<>());
Run Code Online (Sandbox Code Playgroud)
相比之下,以下示例编译:
List<? extends String> list2 = new ArrayList<>();
l.addAll(list2);
Run Code Online (Sandbox Code Playgroud)使用改进的类型检查捕获多个异常类型和重新抛出异常:
在Java SE 7及更高版本中,单个catch块可以处理多种类型的异常.此功能可以减少代码重复.请考虑以下代码,其中包含每个catch块中的重复代码:
catch (IOException e) {
logger.log(e);
throw e;
}
catch (SQLException e) {
logger.log(e);
throw e;
}
Run Code Online (Sandbox Code Playgroud)
在Java SE 7之前的版本中,很难创建一种消除重复代码的常用方法,因为变量e具有不同的类型.以下示例(在Java SE 7及更高版本中有效)消除了重复的代码:
catch (IOException|SQLException e) {
logger.log(e);
throw e;
}
Run Code Online (Sandbox Code Playgroud)
catch子句指定块可以处理的异常类型,每个异常类型用竖线(|)分隔.
java.nio.file包
该java.nio.file包及其相关的包装,java.nio.file.attribute,提供文件I/O和用于访问文件系统的全面支持.JDK 7中也提供了zip文件系统提供程序.
资料来源:http://ohmjavaclasses.blogspot.com/
除了 John Skeet 所说的之外,这里还有Java 7 项目的概述。它包括功能的列表和描述。
注意:JDK 7 于 2011 年 7 月 28 日发布,因此您现在应该访问官方java SE 站点。
| 归档时间: |
|
| 查看次数: |
105458 次 |
| 最近记录: |