Lunch Talk40min
Destructoring is the future of Javas Encapsulation
Project Amber’s “Derived Record/Class Creation” aims to make object deconstruction and reconstruction first-class in Java, fixing serialization’s encapsulation issues. It enables safer, more robust serialization, plus withers and broader pattern matching support for records and normal classes.
talk.summaryAiDisclaimer
Richard GrossMaibornWolff GmbH
talkDetail.whenAndWhere
Monday, October 5, 12:40-13:20
TBA 3
talks.roomOccupancytalks.noOccupancyInfo
Destructoring—the breakdown of an object into its constituent parts—is key to Java's ability to reliably maintain encapsulation and invariants. We resolve this apparent paradox in the presentation by looking at past and future language and platform features in the JDK.
Classic Java serialization breaks encapsulation: it directly accesses private fields, thereby bypassing constructors and the checks anchored there. The reason for this is that deconstruction and reconstruction have not been first-class citizens in the JDK until now.
This is precisely where current work within the JDK Project Amber comes in – under the working title “Derived Record/Class Creation.” This approach allows us to explicitly specify how objects are deconstructed and reconstructed. This will not only make serialization more secure and robust in the future, but we will also gain “withers” (targeted, immutable copies with individual modified components) for records and pattern matching, which will be extended beyond pure record patterns to normal classes.
Given these circumstances, it is worth taking a closer look: What is already there, what comes next – and what does this mean for our daily Java practice?
Classic Java serialization breaks encapsulation: it directly accesses private fields, thereby bypassing constructors and the checks anchored there. The reason for this is that deconstruction and reconstruction have not been first-class citizens in the JDK until now.
This is precisely where current work within the JDK Project Amber comes in – under the working title “Derived Record/Class Creation.” This approach allows us to explicitly specify how objects are deconstructed and reconstructed. This will not only make serialization more secure and robust in the future, but we will also gain “withers” (targeted, immutable copies with individual modified components) for records and pattern matching, which will be extended beyond pure record patterns to normal classes.
Given these circumstances, it is worth taking a closer look: What is already there, what comes next – and what does this mean for our daily Java practice?
Richard Gross
Richard Gross is an IT archaeologist at MaibornWolff with more than ten years of modernization experience. His focus is on hexagonal architectures, hypermedia APIs, TestDSLs and the expressive and unambiguous modelling of the domain as code. He enjoys mastering TDD, BDD, DDD, decoupled design and even practices that don't include two D's. He also shaped the open source project CodeCharta, which lets even non-developers grasp the quality of their software.