jdk7 新特性

来源:互联网 发布:mac怎么同时看两个页面 编辑:程序博客网 时间:2024/05/28 23:09

jdk7 新特性

  1. try with resources or ARM(Automatic Resource Management)
    BufferedReader br = new BufferedReader(new FileReader(path));
    try {
    return br.readLine();
    } finally {
    br.close();
    }

    become:
    try (BufferedReader br = new BufferedReader(new FileReader(path)) {
    return br.readLine();
    }
  2. Strings in switch Statement

    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;}
  3. Multiple Exception Handling(convinent for rethrow)
    } catch (FirstException ex) {
    logger.error(ex);
    throw ex;
    } catch (SecondException ex) {
    logger.error(ex);
    throw ex;
    }
  4. Type Inference for Generic Instance Creation using Diamond Synatax

    } catch (FirstException | SecondException ex) {
    logger.error(ex);
    throw ex;
    }
  5. others(include binary literals, underscore in literals, improved Compile Warnings and Errors)
0 0
原创粉丝点击