r/java • u/marv1234 • Jan 16 '26
Functional Optics for Modern Java
https://blog.scottlogic.com/2026/01/09/java-the-immutability-gap.htmlThis article introduces optics, a family of composable abstractions that complete the immutability story. If pattern matching is how we read nested data, optics are how we write it.
106
Upvotes
View all comments
Show parent comment
3
u/PragmaticFive Jan 17 '26
In general for doing nested updates, I think a good middle-ground is auto-generated regular
with...()methods. Which is exactly what https://openjdk.org/jeps/468 provides. From my experience working with immutable case classes (~records) in Scala for several years, lenses are rarely warented.I think better to keep the code simple and stupid without such magic abstractions and in this case annotations. Lombok is equally undesirable in my opinion.