Skip to main content

Record in Java

1 min read
Share:
On this page (3sections)

Record in Java

Hey Java Buddies, Do you know the record in Java?

πŸ”₯ In Java, the record is identical to the class that acts as a carrier for immutable data. πŸ”₯

πŸ“‚ As per the documentation, records are described as classes that act as transparent carriers for immutable data.Β 

Behaviours and Feature On Java Records

βœ… Help developers to focus on designing immutable data than complex behavior.

βœ… Automatically implement data-driven methods such as equals and accessors.

βœ… Reduce class boilerplate for the immutable classes.

βœ… Design an object-oriented data model construction that describes a simple aggregation of values.

βœ… Maintain long-standing Java principles such as nominal typing and migration compatibility.

βœ… Complete a probable gap in Java’s type system. Provide language-level syntax for a typical programming pattern

Limitations on Java Records

βœ… A record class declaration doesn’t have an extended clause. Its superclass is java.lang.record and cannot inherit from another class.Β 

βœ… A record is final. That means that the state of a record can not be enhanced later by another class using inheritance.

βœ… It is immutable.

βœ… Instance fields are not allowed in a record class.Β 

Note:

πŸ”” Records were suggested and delivered in JDK 14 as a preview feature. Records features were finalized in JDK 16.

Tags:

#java #newfeatures #jdk #records #data #programming #design #language

Related Tutorials

Search tutorials