新版任你发,我用 Java 8,这可能是当下 Java 开发者的真实写照。不过时代可能真的要抛弃 Java 8,全面拥抱 Java 17 了。
SpringBoot 已发布了 3.0.0-M1 版本,并官宣全面拥抱 Java 17,Spring版本要求Spring6,下面的截图是 Release Notes 中的一段:
Github地址:https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-3.0.0-M1-Release-Notes/16c166b5fb4232998a8cfd3966c2851ec1eddf02
Spring Boot 3.0.0-M1 版本发布,也意味着 Spring Boot 进入 3.x 版本的迭代,同时也看到,3.x 版本开始 Spring Boot 要全面拥抱 Java 17 了。
String html = """ <html> <body> <p>Hello, world</p> </body> </html> """;
if (obj instanceof String s) { //这里可以使用 s 变量 } else { //这里不能使用 s 变量 }
Object o; switch (o) { case null -> System.out.println("首先判断对象是否为空,走空指针逻辑等后续逻辑"); case String s -> System.out.println("判断是否为字符串,s:" + s); case record p -> System.out.println("判断是否为Record类型: " + p.toString()); case int[] arr -> System.out.println("判断是否为数组,展示int数组的长度" + ia.length); case Integer i -> System.out.println("判断是否为Intger对象,i:" + i); case Student s -> System.out.println("判断是否为具体学生对象,student:" + s.toString()); case UserCommonService -> System.out.println("判断是否为普通用户实现类,然后走普通用户逻辑"); case UserVipService -> System.out.println("判断是否为vip用户实现类,然后走vip用户逻辑"); default -> System.out.println("Something else"); }
注意:上面的版本只有 Java 11 和 Java 17 是 LTS(Long Term Support) 版本。