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

相关推荐
毕设源码-朱学姐10 小时前
【开题答辩全过程】以 工厂能耗分析平台的设计与实现为例,包含答辩的问题和答案
java·vue.js
Spring AI学习11 小时前
Spring AI深度解析(9/50):可观测性与监控体系实战
java·人工智能·spring
java1234_小锋12 小时前
Spring IoC的实现机制是什么?
java·后端·spring
xqqxqxxq13 小时前
背单词软件技术笔记(V2.0扩展版)
java·笔记·python
消失的旧时光-194313 小时前
深入理解 Java 线程池(二):ThreadPoolExecutor 执行流程 + 运行状态 + ctl 原理全解析
java·开发语言
哈哈老师啊13 小时前
Springboot学生综合测评系统hxtne(程序+源码+数据库+调试部署+开发环境)带论文文档1万字以上,文末可获取,系统界面在最后面。
java·数据库·spring boot
4311媒体网13 小时前
帝国cms调用文章内容 二开基本操作
java·开发语言·php
zwxu_13 小时前
Nginx NIO对比Java NIO
java·nginx·nio
可观测性用观测云15 小时前
Pyroscope Java 接入最佳实践
java
陈小于15 小时前
windows(x86-x64)下编译JCEF
windows