美文网首页
Java 9 小改动

Java 9 小改动

作者: freeseawind | 来源:发表于2018-06-21 00:22 被阅读0次
开发环境
  • eclipse 4.7.3a
  • jdk 9
私有方法上使用 @SafeVarargs 注解
    @SafeVarargs
    private static <T> T getFirst(T... arrays)
    {
        return arrays != null && arrays.length > 0 ? arrays[0] : null;
    }
  • 说明

    可变长度的方法参数实际可通过数组来传递,数组中的对象无法进行类型检查,编译器会给出警告信息,@SafeVarargs 用来忽略编译器的类型警告

更简洁的try-with-resources
try (BufferedReader out = new BufferedReader(new FileReader("")))
{
    System.out.println("hello world!");
}
匿名内部类无需直接指定泛型
 People <String> pepole = new People<>(){}
不能使用 "_" 直接作为标识符
class _{ private int _;} // 错误的范例
允许接口包含私有方法
interface People<T>
{
        private void run()
        {
            //
        }
}

Github工程地址

相关文章

网友评论

      本文标题:Java 9 小改动

      本文链接:https://www.haomeiwen.com/subject/ogpfyftx.html