java 7 中的新特性
java 7 将实现哪些新功能? 他们现在在做什么?
What new features in java 7 is going to be implemented?
And what are they doing now?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
java 7 将实现哪些新功能? 他们现在在做什么?
What new features in java 7 is going to be implemented?
And what are they doing now?
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(8)
Java SE 7 JDK 7 发行说明中的功能和增强功能
这是 OpenJDK 7 功能页面 中的 Java 7 新功能摘要:
Java 1.7 新功能的代码示例
Try-with-resources 语句
如下:
变为:
您可以声明多个要关闭的资源:
数字文字中的下划线
switch 中的字符串
二进制文字
通用实例创建的改进类型推断
变为:
多个异常
捕获此的 :
变成:
SafeVarargs
这个:
变成:
Java SE 7 Features and Enhancements from JDK 7 Release Notes
This is the Java 7 new features summary from the OpenJDK 7 features page:
Code examples for new features in Java 1.7
Try-with-resources statement
this:
becomes:
You can declare more than one resource to close:
Underscores in numeric literals
Strings in switch
Binary literals
Improved Type Inference for Generic Instance Creation
becomes:
Multiple exception catching
this:
becomes:
SafeVarargs
this:
becomes:
Java标准版(JSE 7)的新功能
用JLayer类装饰组件:
JLayer 类是 Swing 组件的灵活而强大的装饰器。 Java SE 7 中的 JLayer 类在本质上与 java.net 上的 JxLayer 项目类似。 JLayer 类最初基于 JXLayer 项目,但其 API 是单独发展的。
switch 语句中的字符串:
在 JDK 7 中,我们可以在 switch 语句的表达式中使用 String 对象。 Java 编译器从使用 String 对象的 switch 语句生成的字节码通常比从链式 if-then-else 语句生成的字节码更有效。
通用实例的类型推断:
只要编译器可以从上下文推断类型参数,我们就可以用一组空的类型参数 (<>) 替换调用泛型类的构造函数所需的类型参数。 这对尖括号非正式地称为菱形。
Java SE 7 支持通用实例创建的有限类型推断; 仅当构造函数的参数化类型从上下文中显而易见时,才可以使用类型推断。 例如,以下示例无法编译:
相比之下,以下示例可以编译:
使用改进的类型检查捕获多个异常类型并重新抛出异常:
在 Java SE 7 及更高版本中,单个 catch 块可以处理多种类型的异常。 此功能可以减少代码重复。 考虑以下代码,其中每个 catch 块中都包含重复的代码:
在 Java SE 7 之前的版本中,由于变量 e 具有不同的类型,因此很难创建通用方法来消除重复代码。
以下示例在 Java SE 7 及更高版本中有效,消除了重复的代码:
catch 子句指定块可以处理的异常类型,每个异常类型用竖线 (|) 分隔。
java.nio.file包
java.nio.file
包及其相关包 java.nio.file.attribute 为文件 I/O 和访问文件系统提供全面的支持。 JDK 7 中还提供了 zip 文件系统提供程序。来源:http://ohmjavaclasses.blogspot.com/
New Feature of Java Standard Edition (JSE 7)
Decorate Components with the JLayer Class:
The JLayer class is a flexible and powerful decorator for Swing components. The JLayer class in Java SE 7 is similar in spirit to the JxLayer project project at java.net. The JLayer class was initially based on the JXLayer project, but its API evolved separately.
Strings in switch Statement:
In the JDK 7 , we can use a String object in the expression of a switch statement. The Java compiler generates generally more efficient bytecode from switch statements that use String objects than from chained if-then-else statements.
Type Inference for Generic Instance:
We can replace the type arguments required to invoke the constructor of a generic class with an empty set of type parameters (<>) as long as the compiler can infer the type arguments from the context. This pair of angle brackets is informally called the diamond.
Java SE 7 supports limited type inference for generic instance creation; you can only use type inference if the parameterized type of the constructor is obvious from the context. For example, the following example does not compile:
In comparison, the following example compiles:
Catching Multiple Exception Types and Rethrowing Exceptions with Improved Type Checking:
In Java SE 7 and later, a single catch block can handle more than one type of exception. This feature can reduce code duplication. Consider the following code, which contains duplicate code in each of the catch blocks:
In releases prior to Java SE 7, it is difficult to create a common method to eliminate the duplicated code because the variable e has different types.
The following example, which is valid in Java SE 7 and later, eliminates the duplicated code:
The catch clause specifies the types of exceptions that the block can handle, and each exception type is separated with a vertical bar (|).
The java.nio.file package
The
java.nio.file
package and its related package, java.nio.file.attribute, provide comprehensive support for file I/O and for accessing the file system. A zip file system provider is also available in JDK 7.Source: http://ohmjavaclasses.blogspot.com/
Java 编程语言增强@ Java7
官方参考
java8 官方参考
维基参考
Java Programming Language Enhancements @ Java7
Official reference
Official reference with java8
wiki reference
除了 John Skeet 所说的之外,这里还有 Java 7 项目概述。 它包括功能的列表和描述。
注意:JDK 7 于 2011 年 7 月 28 日发布,因此您现在应该访问官方 Java SE 站点。
In addition to what John Skeet said, here's an overview of the Java 7 project. It includes a list and description of the features.
Note: JDK 7 was released on July 28, 2011, so you should now go to the official java SE site.
语言变更:
库变更:
平台变更:
下面是解释 JAVA 7 新添加功能的链接,解释非常清楚,每个功能可能的小示例:
http://radar.oreilly.com/2011/ 09/java7-features.html
Language changes:
Library changes:
Platform changes:
Below is the link explaining the newly added features of JAVA 7 , the explanation is crystal clear with the possible small examples for each features :
http://radar.oreilly.com/2011/09/java7-features.html
int val 12_15;
长电话号码 = 01917_999_720L;
int val 12_15;
long phoneNo = 01917_999_720L;
我认为 ForkJoinPool 以及 Executor Framework 的相关增强是 Java 7 中的一个重要补充。
I think ForkJoinPool and related enhancement to Executor Framework is an important addition in Java 7.
以下列表包含 Java SE 7 中增强功能页面的链接。
参考文献1 参考文献2
The following list contains links to the the enhancements pages in the Java SE 7.
Reference 1 Reference 2