<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/the-record-migrate-to-immutability-by-johan-hutting-ku9am1yyt" -->

---
title: The record: migrate to immutability by Johan Hutting
description: Java records, available since Java 16 (LTS in 17 and 21), act as transparent carriers for immutable data and auto-generate constructors, toString, hashCode,...
canonical: https://daily.dev/posts/the-record-migrate-to-immutability-by-johan-hutting-ku9am1yyt
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: The record: migrate to immutability by Johan Hutting | daily.dev
og:description: Java records, available since Java 16 (LTS in 17 and 21), act as transparent carriers for immutable data and auto-generate constructors, toString, hashCode,...
og:url: https://daily.dev/posts/the-record-migrate-to-immutability-by-johan-hutting-ku9am1yyt
og:image: https://api.daily.dev/og/posts/KU9aM1yYt.png
og:image:alt: The record: migrate to immutability by Johan Hutting
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# The record: migrate to immutability by Johan Hutting

**[Devoxx](https://daily.dev/sources/devoxx)** · 14 min read · 0 upvotes · 0 comments

## Summary

Java records, available since Java 16 (LTS in 17 and 21), act as transparent carriers for immutable data and auto-generate constructors, toString, hashCode, and equals methods. A key pitfall is shallow immutability: record fields are immutable references, but mutable objects like ArrayList stored in them can still be modified. To achieve true immutability, use defensive constructors with List.copyOf() (which is free after the first copy since it just copies a pointer for already-immutable lists), or throw exceptions on invalid input. For updating records with changed fields, domain-specific 'wither' methods or Lombok's @With annotation are practical options until JEP 468 (record withers) lands in a future Java release. Migration can be done incrementally using IntelliJ hints or OpenRewrite's 'Lombok Value to Record' recipe. Records reduce cognitive load, help surface hidden mutability bugs, and eliminate the need for Lombok in modern Java projects.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://www.youtube.com/watch?v=JO_XX3YNNRA>

## Similar posts on daily.dev

- [Better Tools for Immutable Data](https://daily.dev/posts/better-tools-for-immutable-data-8vhcosxz3) · Inside Java · 16 upvotes · 0 comments
- [The Java Features That Quietly Save You Tokens](https://daily.dev/posts/the-java-features-that-quietly-save-you-tokens-zh1hl6cfk) · Medium · 10 upvotes · 2 comments
- [You Must Avoid Final Field Mutation](https://daily.dev/posts/you-must-avoid-final-field-mutation-owvllfprz) · nipafx \(Nicolai Parlog\) · 0 upvotes · 0 comments

---

Tags: [#java](https://daily.dev/tags/java)

[View this post on daily.dev](https://daily.dev/posts/the-record-migrate-to-immutability-by-johan-hutting-ku9am1yyt)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"The record: migrate to immutability by Johan Hutting","url":"https://daily.dev/posts/the-record-migrate-to-immutability-by-johan-hutting-ku9am1yyt","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/the-record-migrate-to-immutability-by-johan-hutting-ku9am1yyt"},"datePublished":"2026-04-09T19:33:15.351Z","dateModified":"2026-04-09T19:33:39.272Z","description":"Java records, available since Java 16 (LTS in 17 and 21), act as transparent carriers for immutable data and auto-generate constructors, toString, hashCode,...","image":"https://i.ytimg.com/vi/JO_XX3YNNRA/sddefault.jpg","thumbnailUrl":"https://i.ytimg.com/vi/JO_XX3YNNRA/sddefault.jpg","isAccessibleForFree":true,"articleSection":"Devoxx","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Devoxx","logo":"https://media.daily.dev/image/upload/s--6vG797wn--/f_auto,q_auto/v1773648800/logos/devoxx?_a=BAMAMiiu0","url":"https://daily.dev/sources/devoxx"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/the-record-migrate-to-immutability-by-johan-hutting-ku9am1yyt","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"java","timeRequired":"PT14M","video":{"@type":"VideoObject","name":"The record: migrate to immutability by Johan Hutting","description":"Java records, available since Java 16 (LTS in 17 and 21), act as transparent carriers for immutable data and auto-generate constructors, toString, hashCode,...","thumbnailUrl":"https://i.ytimg.com/vi/JO_XX3YNNRA/sddefault.jpg","uploadDate":"2026-04-09T19:33:15.351Z","duration":"PT14M","url":"https://api.daily.dev/r/KU9aM1yYt","embedUrl":"https://www.youtube.com/embed/JO_XX3YNNRA"}}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Devoxx","item":"https://daily.dev/sources/devoxx"},{"@type":"ListItem","position":3,"name":"The record: migrate to immutability by Johan Hutting"}]}
```

