---
spec: JLS
title: "The Java Language Specification"
edition: "Java SE 23 Edition"
java_version: 23
chapter: "Chapter 8. Classes"
section: "8.10.1"
heading: "8.10.1. Record Components"
parent: "8.10. Record Classes"
source: https://docs.oracle.com/javase/specs/jls/se23/html/jls-8.html#jls-8.10.1
id: "8.10.1"
url: https://jvm.obfuscated.software/jls/se23/8.10.1.html
raw: https://jvm.obfuscated.software/jls/se23/8.10.1.md
---

# 8.10.1. Record Components

The *record components* of a record class, if any, are specified in the header of a record declaration. Each record component consists of a type (optionally preceded by one or more annotations) and an identifier that specifies the name of the record component. A record component corresponds to two members of the record class: a `private` field declared implicitly, and a `public` accessor method declared explicitly or implicitly ([§8.10.3](8.10.3.md)).

If a record class has no record components, then an empty pair of parentheses appears in the header of the record declaration.

```
RecordHeader:
  ( [RecordComponentList] )

RecordComponentList:
  RecordComponent {, RecordComponent}

RecordComponent:
  {RecordComponentModifier} UnannType Identifier
  VariableArityRecordComponent

VariableArityRecordComponent:
  {RecordComponentModifier} UnannType {Annotation} ... Identifier

RecordComponentModifier:
  Annotation
```

A record component may be a *variable arity record component*, indicated by an ellipsis following the type. At most one variable arity record component is permitted for a record class. It is a compile-time error if a variable arity record component appears anywhere in the list of record components except the last position.

The rules concerning annotation modifiers for a record component are specified in [§9.7.4](9.7.4.md) and [§9.7.5](9.7.5.md).

Annotations on a record component are available via reflection if their annotation interfaces are applicable in the record component context ([§9.6.4.1](9.6.4.1.md)). Independently, annotations on a record component are propagated to the declarations of members and constructors of the record class if their annotation interfaces are applicable in other contexts ([§8.10.3](8.10.3.md), [§8.10.4](8.10.4.md)).

Every declaration of a record component must include an *Identifier*, otherwise a compile-time error occurs.

It is a compile-time error for a record declaration to have a record component with the name `clone`, `finalize`, `getClass`, `hashCode`, `notify`, `notifyAll`, `toString`, or `wait`.

These are the names of the no-args `public` and `protected` methods in `Object`. Disallowing them as the names of record components avoids confusion in a number of ways. First, every record class provides implementations of `hashCode` and `toString` that return representations of a record object as a whole; they cannot serve as accessor methods ([§8.10.3](8.10.3.md)) for record components called `hashCode` or `toString`, and there would be no way to access such record components from outside the record class. Similarly, some record classes may provide implementations of `clone` and (regrettably) `finalize`, so a record component called `clone` or `finalize` could not be accessed via an accessor method. Finally, the `getClass`, `notify`, `notifyAll`, and `wait` methods in `Object` are `final`, so record components with the same names could not have accessor methods. (The accessor methods would have the same signatures as the `final` methods, and would thus attempt, unsuccessfully, to override them.)

It is a compile-time error for a record declaration to have two record components with the same name.

The declared type of a record component depends on whether it is a variable arity record component:

- If the record component is not a variable arity record component, then the declared type is denoted by *UnannType*.
- If the record component is a variable arity record component, then the declared type is an array type specified by [§10.2](10.2.md).

If the declared type of a variable arity record component has a non-reifiable element type ([§4.7](4.7.md)), then a compile-time unchecked warning occurs for the declaration of the variable arity record component, unless the canonical constructor ([§8.10.4](8.10.4.md)) is annotated with `@SafeVarargs` ([§9.6.4.7](9.6.4.7.md)) or the warning is suppressed by `@SuppressWarnings` ([§9.6.4.5](9.6.4.5.md)).
