Records with Local Variable Type Inference (introduced in Java 16)

 Records with Local Variable Type Inference (introduced in Java 16)


Java 16 introduced the combination of records and local variable type inference, allowing you to declare record instances with inferred types. Here's an example:


record Person(String name, int age) {}


var person = new Person("John Doe", 30);

System.out.println(person.name()); // John Doe

System.out.println(person.age()); // 30

No comments:

Post a Comment

The Importance of Cybersecurity in the Digital Age

 The Importance of Cybersecurity in the Digital Age Introduction: In today's digital age, where technology is deeply intertwined with ev...