Prev Next

Java / Java Record Keyword

What is a record keyword in Java?

A record in Java is a special type of class designed to concisely model data. Introduced in Java 16, records automatically generate essential methods, reducing boilerplate code. Here's how to define and use them:

Defining a Record:

Records are declared using the record keyword, followed by the record name and component list within parentheses.

 record Person(String name, int age) {}

This creates a Person record with two components: name (String) and age (int).

More Related questions...

Show more question and Answers...


Comments & Discussions