java 7中的新功能 [英] New features in java 7

查看:90
本文介绍了java 7中的新功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将实施java 7中的哪些新功能?
他们现在在做什么?

What new features in java 7 is going to be implemented? And what are they doing now?

推荐答案

Java SE 7 功能和增强功能



这是来自 OpenJDK 7功能页面的Java 7新功能摘要:

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:



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]




Java 1.7中新功能的代码示例



试用资源声明



这个:

Code examples for new features in Java 1.7

Try-with-resources statement

this:

BufferedReader br = new BufferedReader(new FileReader(path));
try {
   return br.readLine();
} finally {
   br.close();
}

成为:

try (BufferedReader br = new BufferedReader(new FileReader(path)) {
   return br.readLine();
}

您可以声明要关闭的多个资源:

You can declare more than one resource to close:

try (
   InputStream in = new FileInputStream(src);
   OutputStream out = new FileOutputStream(dest))
{
 // code
}



数字文字中的下划线



Underscores in numeric literals

int one_million = 1_000_000;



开关中的字符串



Strings in switch

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;
}



二进制文字



Binary literals

int binary = 0b1001_1001;



改进通用实例创建的类型推断



Improved Type Inference for Generic Instance Creation

Map<String, List<String>> anagrams = new HashMap<String, List<String>>();

变为:

Map<String, List<String>> anagrams = new HashMap<>();



多个异常捕获



这个:

Multiple exception catching

this:

} catch (FirstException ex) {
     logger.error(ex);
     throw ex;
} catch (SecondException ex) {
     logger.error(ex);
     throw ex;
}

成为:

} catch (FirstException | SecondException ex) {
     logger.error(ex);
    throw ex;
}



SafeVarargs



这个:

SafeVarargs

this:

@SuppressWarnings({"unchecked", "varargs"})
public static void printAll(List<String>... lists){
    for(List<String> list : lists){
        System.out.println(list);
    }
}

变为:

@SafeVarargs
public static void printAll(List<String>... lists){
    for(List<String> list : lists){
        System.out.println(list);
    }
}

这篇关于java 7中的新功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆