Java9 新特性

更简洁的 try-with-resources 语句

现在可以把变量声明在外面,try-with-resources语句里只写引用了

Scanner s = new Scanner(System.in);
// try(Scanner s = new Scanner(System.in))
try (s) {
    s.next();
} catch (Exception e) {
    e.printStackTrace();
}

_ 不再是一个合法的变量名

java9不允许以一条下划线作为变量名

int _ = 1; // error

接口中允许定义private方法

不能是abstract的

interface Inter {
    private void method(){

    }
}

这是为了让非abstract方法间可以复用代码

<> 可以与匿名内部类一起使用了

就像这样

// Comparator c = new Comparator() {
Comparator c = new Comparator<>() {
    @Override
    public int compare(Integer o1, Integer o2) {
        return 0;
    }
};

@SafeVarargs 允许用在私有实例方法中

class C{
    @SafeVarargs
    private void method(T ...s){

    }   
}

你可能感兴趣的:(研究记录)