APIdia Launch Partner
Top Description Constructors Methods
java.lang

public abstract Class Record

extends Object
Class Inheritance
Known Direct Subclasses
java.lang.runtime.Carriers.CarrierCounts, java.lang.runtime.SwitchBootstraps.TypePairs, java.util.Formatter.FixedString, java.util.LazyCollections.AbstractLazyMap.LazyEntry, java.lang.invoke.MethodHandleProxies.MethodInfo, java.lang.invoke.InvokerBytecodeGenerator.ClassData, java.lang.invoke.MethodHandles.Lookup.ClassDefiner, java.lang.invoke.StringConcatFactory.InlineHiddenClassStrategy.MethodHandlePair, java.lang.reflect.Executable.ParameterData, java.lang.reflect.Proxy.ProxyBuilder.ProxyClassContext, java.nio.DirectByteBuffer.Deallocator, java.security.SecureClassLoader.CodeSourceKey, java.text.DecimalFormat.NumericPosition, java.util.concurrent.StructuredTaskScopeImpl.SubtaskImpl.AltResult, java.util.concurrent.StructuredTaskScopeImpl.ConfigImpl, java.util.random.RandomGeneratorFactory.RandomGeneratorProperties, java.util.stream.Collectors.CollectorImpl, java.util.stream.Gatherers.GathererImpl, java.util.zip.ZipFile.EntryPos, javax.crypto.KDF.Delegate, com.sun.crypto.provider.DHKEM.Handler, com.sun.crypto.provider.ML_KEM.K_PKE_EncryptionKey, com.sun.crypto.provider.ML_KEM.K_PKE_DecryptionKey, com.sun.crypto.provider.ML_KEM.K_PKE_KeyPair, com.sun.crypto.provider.ML_KEM.K_PKE_CipherText, com.sun.crypto.provider.ML_KEM.ML_KEM_EncapsulationKey, com.sun.crypto.provider.ML_KEM.ML_KEM_DecapsulationKey, com.sun.crypto.provider.ML_KEM.ML_KEM_KeyPair, com.sun.crypto.provider.ML_KEM.ML_KEM_EncapsulateResult, com.sun.crypto.provider.PKCS12PBECipherCore.KeyAndIv, jdk.internal.foreign.BufferStack.PerThread, jdk.internal.foreign.BufferStack.PerThread.CleanupAction, jdk.internal.foreign.CaptureStateUtil.SegmentExtractorKey, jdk.internal.foreign.LayoutPath.GroupElementByName, jdk.internal.foreign.LayoutPath.GroupElementByIndex, jdk.internal.foreign.LayoutPath.SequenceElementByIndex, jdk.internal.foreign.LayoutPath.SequenceElementByRange, jdk.internal.foreign.LayoutPath.SequenceElement, jdk.internal.foreign.LayoutPath.DereferenceElement, jdk.internal.foreign.Utils.BaseAndScale, jdk.internal.misc.ThreadTracker.ThreadRef, jdk.internal.module.ModuleReferenceImpl.CachedHash, jdk.internal.reflect.ReflectionFactory.Config, jdk.internal.util.ImmutableBitSetPredicate.SmallImmutableBitSetPredicate, jdk.internal.util.OSVersion, jdk.internal.vm.ScopedValueContainer.BindingsSnapshot, jdk.internal.vm.ThreadSnapshot.ThreadBlocker, sun.nio.ch.IOUtil.LinkedRunnable, sun.nio.ch.IOUtil.Releaser, sun.nio.ch.Poller.PollerPerCarrierPollerGroup.CarrierPoller, sun.security.pkcs.PKCS9Attribute.AttributeInfo, sun.security.pkcs.SignerInfo.AlgorithmInfo, sun.security.provider.ML_DSA.ML_DSA_PrivateKey, sun.security.provider.ML_DSA.ML_DSA_PublicKey, sun.security.provider.ML_DSA.ML_DSA_KeyPair, sun.security.provider.ML_DSA.ML_DSA_Signature, sun.security.provider.NamedKEM.KeyConsumerImpl, sun.security.util.KeyChoices.Choice, sun.security.util.KeyUtil.RawPublicKey, sun.util.locale.LanguageTag, jdk.internal.classfile.impl.AbstractInstruction.SwitchCaseImpl, jdk.internal.classfile.impl.AnnotationImpl, jdk.internal.classfile.impl.AnnotationImpl.AnnotationElementImpl, jdk.internal.classfile.impl.AnnotationImpl.OfStringImpl, jdk.internal.classfile.impl.AnnotationImpl.OfDoubleImpl, jdk.internal.classfile.impl.AnnotationImpl.OfFloatImpl, jdk.internal.classfile.impl.AnnotationImpl.OfLongImpl, jdk.internal.classfile.impl.AnnotationImpl.OfIntImpl, jdk.internal.classfile.impl.AnnotationImpl.OfShortImpl, jdk.internal.classfile.impl.AnnotationImpl.OfCharImpl, jdk.internal.classfile.impl.AnnotationImpl.OfByteImpl, jdk.internal.classfile.impl.AnnotationImpl.OfBooleanImpl, jdk.internal.classfile.impl.AnnotationImpl.OfArrayImpl, jdk.internal.classfile.impl.AnnotationImpl.OfEnumImpl, jdk.internal.classfile.impl.AnnotationImpl.OfAnnotationImpl, jdk.internal.classfile.impl.AnnotationImpl.OfClassImpl, jdk.internal.classfile.impl.ClassFileImpl.AttributeMapperOptionImpl, jdk.internal.classfile.impl.ClassFileImpl.ClassHierarchyResolverOptionImpl, jdk.internal.classfile.impl.ClassPrinterImpl.LeafNodeImpl, jdk.internal.classfile.impl.ClassPrinterImpl.ExceptionHandler, jdk.internal.classfile.impl.ClassRemapperImpl, jdk.internal.classfile.impl.CodeRelabelerImpl, jdk.internal.classfile.impl.CodeStackTrackerImpl.Item, jdk.internal.classfile.impl.DirectCodeBuilder.DeferredLabel, jdk.internal.classfile.impl.RawBytecodeHelper.CodeRange, jdk.internal.classfile.impl.SignaturesImpl.BaseTypeSigImpl, jdk.internal.classfile.impl.SignaturesImpl.TypeVarSigImpl, jdk.internal.classfile.impl.SignaturesImpl.ArrayTypeSigImpl, jdk.internal.classfile.impl.SignaturesImpl.ClassTypeSigImpl, jdk.internal.classfile.impl.SignaturesImpl.TypeArgImpl, jdk.internal.classfile.impl.SignaturesImpl.TypeParamImpl, jdk.internal.classfile.impl.SignaturesImpl.ClassSignatureImpl, jdk.internal.classfile.impl.SignaturesImpl.MethodSignatureImpl, jdk.internal.classfile.impl.StackCounter.Target, jdk.internal.classfile.impl.StackMapDecoder.ObjectVerificationTypeInfoImpl, jdk.internal.classfile.impl.StackMapDecoder.UninitializedVerificationTypeInfoImpl, jdk.internal.classfile.impl.StackMapDecoder.StackMapFrameImpl, jdk.internal.classfile.impl.StackMapGenerator.RawExceptionCatch, jdk.internal.classfile.impl.StackMapGenerator.Type, jdk.internal.classfile.impl.TargetInfoImpl.TypeParameterTargetImpl, jdk.internal.classfile.impl.TargetInfoImpl.SupertypeTargetImpl, jdk.internal.classfile.impl.TargetInfoImpl.TypeParameterBoundTargetImpl, jdk.internal.classfile.impl.TargetInfoImpl.EmptyTargetImpl, jdk.internal.classfile.impl.TargetInfoImpl.FormalParameterTargetImpl, jdk.internal.classfile.impl.TargetInfoImpl.ThrowsTargetImpl, jdk.internal.classfile.impl.TargetInfoImpl.LocalVarTargetImpl, jdk.internal.classfile.impl.TargetInfoImpl.LocalVarTargetInfoImpl, jdk.internal.classfile.impl.TargetInfoImpl.CatchTargetImpl, jdk.internal.classfile.impl.TargetInfoImpl.OffsetTargetImpl, jdk.internal.classfile.impl.TargetInfoImpl.TypeArgumentTargetImpl, jdk.internal.classfile.impl.TransformImpl.ResolvedTransform, jdk.internal.classfile.impl.TransformImpl.ChainedClassTransform, jdk.internal.classfile.impl.TransformImpl.SupplierClassTransform, jdk.internal.classfile.impl.TransformImpl.ClassMethodTransform, jdk.internal.classfile.impl.TransformImpl.ClassFieldTransform, jdk.internal.classfile.impl.TransformImpl.ChainedMethodTransform, jdk.internal.classfile.impl.TransformImpl.SupplierMethodTransform, jdk.internal.classfile.impl.TransformImpl.MethodCodeTransform, jdk.internal.classfile.impl.TransformImpl.ChainedFieldTransform, jdk.internal.classfile.impl.TransformImpl.SupplierFieldTransform, jdk.internal.classfile.impl.TransformImpl.ChainedCodeTransform, jdk.internal.classfile.impl.TransformImpl.SupplierCodeTransform, jdk.internal.classfile.impl.UnboundAttribute.UnboundCharacterRangeInfo, jdk.internal.classfile.impl.UnboundAttribute.UnboundInnerClassInfo, jdk.internal.classfile.impl.UnboundAttribute.UnboundLineNumberInfo, jdk.internal.classfile.impl.UnboundAttribute.UnboundLocalVariableInfo, jdk.internal.classfile.impl.UnboundAttribute.UnboundLocalVariableTypeInfo, jdk.internal.classfile.impl.UnboundAttribute.UnboundMethodParameterInfo, jdk.internal.classfile.impl.UnboundAttribute.UnboundModuleExportInfo, jdk.internal.classfile.impl.UnboundAttribute.UnboundModuleHashInfo, jdk.internal.classfile.impl.UnboundAttribute.UnboundModuleOpenInfo, jdk.internal.classfile.impl.UnboundAttribute.UnboundModuleProvideInfo, jdk.internal.classfile.impl.UnboundAttribute.UnboundModuleRequiresInfo, jdk.internal.classfile.impl.UnboundAttribute.UnboundRecordComponentInfo, jdk.internal.classfile.impl.UnboundAttribute.UnboundTypeAnnotation, jdk.internal.classfile.impl.UnboundAttribute.TypePathComponentImpl, jdk.internal.classfile.impl.ClassHierarchyImpl.ClassHierarchyInfoImpl, jdk.internal.classfile.impl.verifier.ParserVerifier, jdk.internal.constant.ModuleDescImpl, jdk.internal.constant.PackageDescImpl, jdk.internal.foreign.abi.AbstractLinker.LinkRequest, jdk.internal.foreign.abi.Binding.VMStore, jdk.internal.foreign.abi.Binding.VMLoad, jdk.internal.foreign.abi.Binding.BufferStore, jdk.internal.foreign.abi.Binding.BufferLoad, jdk.internal.foreign.abi.Binding.Copy, jdk.internal.foreign.abi.Binding.Allocate, jdk.internal.foreign.abi.Binding.SegmentBase, jdk.internal.foreign.abi.Binding.SegmentOffset, jdk.internal.foreign.abi.Binding.BoxAddress, jdk.internal.foreign.abi.Binding.Dup, jdk.internal.foreign.abi.Binding.ShiftLeft, jdk.internal.foreign.abi.Binding.ShiftRight, jdk.internal.foreign.abi.DowncallLinker.InvocationData, jdk.internal.foreign.abi.LinkerOptions.FirstVariadicArg, jdk.internal.foreign.abi.LinkerOptions.CaptureCallState, jdk.internal.foreign.abi.NativeEntryPoint.CacheKey, jdk.internal.foreign.abi.UpcallLinker.InvocationData, jdk.internal.foreign.abi.UpcallLinker.CallRegs, jdk.internal.foreign.abi.VMStorage, jdk.internal.foreign.abi.aarch64.CallArranger.Bindings, jdk.internal.foreign.abi.aarch64.CallArranger.StorageCalculator.StructStorage, jdk.internal.foreign.abi.fallback.FallbackLinker.DowncallData, jdk.internal.foreign.abi.fallback.FallbackLinker.UpcallData, jdk.internal.foreign.abi.ppc64.CallArranger.Bindings, jdk.internal.foreign.abi.ppc64.CallArranger.HfaRegs, jdk.internal.foreign.abi.riscv64.linux.LinuxRISCV64CallArranger.Bindings, jdk.internal.foreign.abi.riscv64.linux.TypeClass.FieldCounter, jdk.internal.foreign.abi.riscv64.linux.TypeClass.FlattenedFieldDesc, jdk.internal.foreign.abi.s390.linux.LinuxS390CallArranger.Bindings, jdk.internal.foreign.abi.x64.sysv.CallArranger.Bindings, jdk.internal.foreign.abi.x64.windows.CallArranger.Bindings, sun.security.ssl.CompressedCertificate.CompCertCacheKey, sun.security.ssl.Hybrid.Handler, sun.security.ssl.Hybrid.SecretKeyImpl, sun.security.ssl.Hybrid.PublicKeyImpl, sun.security.ssl.Hybrid.PrivateKeyImpl, sun.security.ssl.QuicKeyManager.QuicKeys, sun.security.ssl.QuicKeyManager.CipherPair, sun.security.ssl.QuicKeyManager.OneRttKeyManager.KeySeries, java.lang.ClassValue.Version

This is the common base class of all Java language record classes.

More information about records, including descriptions of the implicitly declared methods synthesized by the compiler, can be found in section 8.10 of The Java Language Specification.

A record class is a shallowly immutable, transparent carrier for a fixed set of values, called the record components. The Java language provides concise syntax for declaring record classes, whereby the record components are declared in the record header. The list of record components declared in the record header form the record descriptor.

A record class has the following mandated members: a canonical constructor, which must provide at least as much access as the record class and whose descriptor is the same as the record descriptor; a private final field corresponding to each component, whose name and type are the same as that of the component; a public accessor method corresponding to each component, whose name and return type are the same as that of the component. If not explicitly declared in the body of the record, implicit implementations for these members are provided.

The implicit declaration of the canonical constructor has the same accessibility as the record class and initializes the component fields from the corresponding constructor arguments. The implicit declaration of the accessor methods returns the value of the corresponding component field. The implicit declaration of the Object#equals(Object), Object#hashCode(), and Object#toString() methods are derived from all of the component fields.

The primary reasons to provide an explicit declaration for the canonical constructor or accessor methods are to validate constructor arguments, perform defensive copies on mutable components, or normalize groups of components (such as reducing a rational number to lowest terms.)

For all record classes, the following invariant must hold: if a record R's components are c1, c2, ... cn, then if a record instance is copied as follows:

    R copy = new R(r.c1(), r.c2(), ..., r.cn());
then it must be the case that r.equals(copy).

API Note

A record class that implements java.io.Serializable is said to be a serializable record. Serializable records are serialized and deserialized differently than ordinary serializable objects. During deserialization the record's canonical constructor is invoked to construct the record object. Certain serialization-related methods, such as readObject and writeObject, are ignored for serializable records. More information about serializable records can be found in the Java Object Serialization Specification, Section 1.13, "Serialization of Records".

API Note

A record class structure can be obtained at runtime via reflection. See Class#isRecord() and Class#getRecordComponents() for more details.

Since
16
Java Language Specification
8.10 Record Classes
External Specification
Java Object Serialization Specification

Constructor Summary

AccessConstructor and Description
protected
Record()

Constructor for record classes to call.

Method Summary

Modifier and TypeMethod and Description
public abstract boolean

Returns:

true if this record is equal to the argument; false otherwise.
equals
(Object
the reference object with which to compare.
obj
)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

public abstract int

Returns:

a hash code value for this record.
hashCode
()

Overrides java.lang.Object.hashCode.

Returns a hash code value for the record.

public abstract String

Returns:

a string representation of the object.
toString
()

Overrides java.lang.Object.toString.

Returns a string representation of the record.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Constructor Detail

Recordback to summary
protected Record()

Constructor for record classes to call.

Method Detail

equalsback to summary
public abstract boolean equals(Object obj)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one. In addition to the general contract of Object.equals, record classes must further obey the invariant that when a record instance is "copied" by passing the result of the record component accessor methods to the canonical constructor, as follows:

    R copy = new R(r.c1(), r.c2(), ..., r.cn());
then it must be the case that r.equals(copy).

Implementation Specification

The implicitly provided implementation returns true if and only if the argument is an instance of the same record class as this record, and each component of this record is equal to the corresponding component of the argument; otherwise, false is returned. Equality of a component c is determined as follows:

  • If the component is of a reference type, the component is considered equal if and only if Objects.equals(this.c, r.c) would return true.
  • If the component is of a primitive type, using the corresponding primitive wrapper class PW (the corresponding wrapper class for int is java.lang.Integer, and so on), the component is considered equal if and only if PW.compare(this.c, r.c) would return 0.
Note that these rules imply that representation equivalence is used for the equality comparison of both primitive floating-point values and wrapped floating-point values.

Apart from the semantics described above, the precise algorithm used in the implicitly provided implementation is unspecified and is subject to change. The implementation may or may not use calls to the particular methods listed, and may or may not perform comparisons in the order of component declaration.

Parameters
obj:Object

the reference object with which to compare.

Returns:boolean

true if this record is equal to the argument; false otherwise.

Annotations
@Override
See Also
java.util.Objects#equals(Object, Object)
hashCodeback to summary
public abstract int hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for the record. Obeys the general contract of Object.hashCode. For records, hashing behavior is constrained by the refined contract of Record.equals, so that any two records created from the same components must have the same hash code.

Implementation Specification

The implicitly provided implementation returns a hash code value derived by combining appropriate hashes from each component. The precise algorithm used in the implicitly provided implementation is unspecified and is subject to change within the above limits. The resulting integer need not remain consistent from one execution of an application to another execution of the same application, even if the hashes of the component values were to remain consistent in this way. Also, a component of primitive type may contribute its bits to the hash code differently than the hashCode of its primitive wrapper class.

Returns:int

a hash code value for this record.

Annotations
@Override
See Also
Object#hashCode()
toStringback to summary
public abstract String toString()

Overrides java.lang.Object.toString.

Returns a string representation of the record. In accordance with the general contract of Object#toString(), the toString method returns a string that "textually represents" this record. The result should be a concise but informative representation that is easy for a person to read.

In addition to this general contract, record classes must further participate in the invariant that any two records which are equal must produce equal strings. This invariant is necessarily relaxed in the rare case where corresponding equal component values might fail to produce equal strings for themselves.

Implementation Specification

The implicitly provided implementation returns a string which contains the name of the record class, the names of components of the record, and string representations of component values, so as to fulfill the contract of this method. The precise format produced by this implicitly provided implementation is subject to change, so the present syntax should not be parsed by applications to recover record component values.

Returns:String

a string representation of the object.

Annotations
@Override
See Also
Object#toString()