Java8核心特性速览✅Lambda 表达式- 函数式编程基础✅函数式接口-FunctionalInterface注解✅方法引用-Class::method语法✅默认/静态方法- 接口可定义实现✅Stream API- 声明式集合操作✅新日期时间 API-java.time包线程安全、不可变✅Optional 类- 避免空指针异常重点代码示例Lambda 表达式Arrays.asList(a, b, d).forEach(e - System.out.println(e));Stream API// 创建流 StreamInteger stream Stream.of(1, 2, 3); StreamString fromString Stream.of(taobao); // 并行流性能提升 long start System.nanoTime(); values.parallelStream().sorted().count(); // 比串行快约 50%OptionalOptionalString opt Optional.ofNullable(value); opt.ifPresent(System.out::println);新日期时间 APIjava17核心特性速览✅Record Classes- 不可数据类✅Sealed Classes/Interfaces- 限制继承✅Pattern Matching for switch- instanceof switch✅Foreign Function Memory API(预览)✅强封装 JDK 内部- 更好的安全性重点代码示例Record Classpublic record Point(int x, int y) {} Point p new Point(1, 2); System.out.println(p.x()); // 访问器 System.out.println(p.toString()); // 自动生成 toStringSealed Classespublic sealed class Shape permits Circle, Rectangle {} public final class Circle extends Shape {} public final class Rectangle extends Shape {}Pattern Matching for switchif (obj instanceof String s) { System.out.println(s.toLowerCase()); } // switch 中的模式匹配 return switch (obj) { case Integer i - i * 2; case String s - s.length(); default - throw new IllegalArgumentException(); };LocalDate today LocalDate.now(); LocalTime now LocalTime.now(); LocalDateTime combined LocalDateTime.of(2014, Month.DECEMBER, 31, 23, 59, 59); Clock clock Clock.systemDefaultZone(); Instant instant clock.instant();