其他
是时候用Java 17了
关于从先前的长期支持版本(Java 11 和 Java 8)迁移代码,你需要知道的是什么?
Java 17+(来自 Spring Framework 5.3.x 线中的 Java 8-17) Jakarta EE 9+(来自Spring框架5.3.x 线中的 Java EE 7-8)
public class Application {
public static void main(String[] args) {
Student student = new Student("James ");
System.out.println("Implementation " + student.implementation());
System.out.println("Student name James contains a blank: " + student.isBlankName());
}
}
public class Student {final private String firstName;public Student(String firstName) {this.firstName = firstName; }boolean isBlankName() {return firstName == null || firstName.trim().isEmpty(); }static String implementation() { return "class"; }}
public record Student(String firstName) {boolean isBlankName() {return firstName.isBlank(); }static String implementation() { return "record"; }}
——add-opens = jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED