0 day streak
java / beginner
Snippet

Defining a Data Record

Java Records are a modern way to create classes that only hold data. They automatically provide constructors, getters, and methods like equals() and hashCode().

snippet.java
java
1
2
3
public record UserDto(String username, String email) {
// Records are immutable and concise
}
spring
Breakdown
1
public record UserDto
Declares a record which is a special type of class optimized for data storage.
2
(String username, String email)
The state description which automatically generates private final fields.