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 要兼容,另一方面代码习惯,明了比简洁还要重要。

相关推荐
大明者省3 小时前
多类别分类中,标签的 “独热编码” 形式与输出层神经元的位置处理过程
1024程序员节
Wind哥3 小时前
设计模式23种-C++实现
开发语言·c++·windows·设计模式
不平衡的叉叉树3 小时前
mybatis-plus的insertBatchSomeColumn方法实现批量插入
java·mybatis
Bruce_Liuxiaowei3 小时前
[特殊字符] 排查VMnet1无IP的步骤
网络·网络协议·1024程序员节
学IT的周星星3 小时前
Maven 项目和 Maven Web 项目的异同点
java·maven
摇滚侠3 小时前
Spring Boot3零基础教程,函数式 Web 新特性,笔记51
java·spring boot·笔记
mustfeng3 小时前
VCS & Verdi 2023安装
java·服务器·前端
Geoffrey4 小时前
maven中的pom详述
java
练习时长一年4 小时前
jdk动态代理实现
java·开发语言