← All Exercises

Record Class for DTOs

basicjava~10min

Background

Records reduce boilerplate for immutable data carriers in Java applications.

Problem

Create a record class for a data transfer object with automatic accessor methods and validation.

Input

Field values for the record

Output

Immutable record instance

Sample tests

Sample 1

Input: new Point(3, 4)
Expected: Point[x=3, y=4]

Your solution

Learning objective

Learn Java records and compact constructors