Record in Java
✍ Definition
✍ 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