JDK 9 List.of(...)

复制代码
		// JDK 9      写法: List.of(...)
//		List<Point> polygon = List.of(new Point(0, 0), new Point(0, 4), new Point(4, 4), new Point(4, 0));

		// JDK 1.6 写法:使用ArrayList并手动add元素
		List<Point> polygon = new ArrayList<Point>();
		polygon.add(new Point(0, 0));
		polygon.add(new Point(0, 4));
		polygon.add(new Point(4, 4));
		polygon.add(new Point(4, 0));
html 复制代码
JDK 9 List.of(...)

JDK 1.6            boolean add(E e);
复制代码
/**
     * Appends the specified element to the end of this list (optional
     * operation).
     *
     * <p>Lists that support this operation may place limitations on what
     * elements may be added to this list.  In particular, some
     * lists will refuse to add null elements, and others will impose
     * restrictions on the type of elements that may be added.  List
     * classes should clearly specify in their documentation any restrictions
     * on what elements may be added.
     *
     * @param e element to be appended to this list
     * @return <tt>true</tt> (as specified by {@link Collection#add})
     * @throws UnsupportedOperationException if the <tt>add</tt> operation
     *         is not supported by this list
     * @throws ClassCastException if the class of the specified element
     *         prevents it from being added to this list
     * @throws NullPointerException if the specified element is null and this
     *         list does not permit null elements
     * @throws IllegalArgumentException if some property of this element
     *         prevents it from being added to this list
     */
    boolean add(E e);

没有什么为什么,一方面以前做的项目1.6 1.8 要兼容,另一方面代码习惯,明了比简洁还要重要。

相关推荐
一定要AK5 小时前
Spring 入门核心笔记
java·笔记·spring
A__tao5 小时前
Elasticsearch Mapping 一键生成 Java 实体类(支持嵌套 + 自动过滤注释)
java·python·elasticsearch
KevinCyao5 小时前
java视频短信接口怎么调用?SpringBoot集成视频短信及回调处理Demo
java·spring boot·音视频
航Hang*5 小时前
Windows Server 配置与管理——第3章:文件系统管理
运维·服务器·windows·vmware
迷藏4945 小时前
**发散创新:基于Rust实现的开源合规权限管理框架设计与实践**在现代软件架构中,**权限控制(RBAC)** 已成为保障
java·开发语言·python·rust·开源
wuxinyan1236 小时前
Java面试题47:一文深入了解Nginx
java·nginx·面试题
新知图书7 小时前
搭建Spring Boot开发环境
java·spring boot·后端
冰河团队7 小时前
一个拉胯的分库分表方案有多绝望?整个部门都在救火!
java·高并发·分布式数据库·分库分表·高性能
洛_尘7 小时前
Java EE进阶:Linux的基本使用
java·java-ee
无限进步_7 小时前
【C++】电话号码的字母组合:从有限处理到通用解法
开发语言·c++·ide·windows·git·github·visual studio