Syntax

Java Define a Record Syntax

In Java, define a record: defines an immutable data class in one line — record Point(int x, int y) {}

Quick Answer

Syntax
record Point(int x, int y) {}
JavaSyntax

Define a Record

Code example
record Point(int x, int y) {}

Defines an immutable data class in one line.

Learn More

How to define a record in Java

  1. Open your Java file or editor.
  2. Copy the example, then replace its sample names and values for your code.

Java Define a Record Syntax

Use record Point(int x, int y) {}.

Related Syntax References

Frequently asked questions

What is the Java syntax for define a record?

Use this pattern: record Point(int x, int y) {}

Can I copy this Java code example?

Yes. Use Copy code and adapt the example to your program.

Is this Java syntax different on Mac or Windows?

No. The language syntax is the same across operating systems.

Official source · How we verify