Java 14 introduces a new class type record as preview feature to facilitate creation of immutable data objects. Java 15 enhances record type further. With Java 16, record is now a standard feature of JDK.
Consider the following example −
Java16Tester.java
Example
public class Java16Tester {
public static void main(String[] args) {
StudentRecord student = new StudentRecord (1, "Elavarasan", "Red", "VI", 12);
System.out.println(student.id());
System.out.println(student.name());
System.out.println(student);
}
}
record StudentRecord(int id,
String name,
String section,
String className,
int age){}
Compile and Run the program
$javac Java16Tester.java
$java Java16Tester
Output
1
Julie
StudentRecord[id=1, name=Elavarasan, section=Red, className=VI, age=12]