Balkrishna Rawool
Algebraic Data Types + Pattern Matching = Elegant and readable Java code
#1about 2 minutes
Introducing the 'SEND + MORE = MONEY' puzzle
A cryptarithmetic puzzle is presented where letters represent unique digits in a mathematical equation that must be solved.
#2about 3 minutes
Designing a solver and defining an expression grammar
A high-level solution is designed with a generator and evaluator, based on a grammar that defines expressions as constants, variables, additions, or multiplications.
#3about 4 minutes
Understanding algebraic data types and pattern matching in Java
Product types are implemented with records and sum types with sealed interfaces, which can then be deconstructed using pattern matching for `instanceof` and `switch`.
#4about 2 minutes
Modeling expressions as an algebraic data type
An expression is modeled as a sum type using a Java sealed interface with record implementations for constant, variable, addition, and multiplication.
#5about 3 minutes
Implementing an evaluation function with pattern matching
A static `evaluate` function uses a pattern matching switch expression to recursively calculate the value of an expression tree, ensuring compile-time safety.
#6about 8 minutes
Building the puzzle solver and constraints
The main puzzle solver logic is built by creating a sealed interface for constraints and using a generator to check all combinations against them.
#7about 4 minutes
Assembling and running the puzzle solution test
A unit test is created to assemble the puzzle's variables, expressions, and constraints, which is then run to find and verify the final solution.
#8about 1 minute
The pattern of data-oriented programming in Java
The combination of algebraic data types for data modeling and pattern matching for behavior is defined as data-oriented programming, a powerful pattern for writing readable code.
Related jobs
Jobs that call for the skills explored in this talk.
MARKT-PILOT GmbH
Stuttgart, Germany
Remote
€75-90K
Senior
Java
TypeScript
+1
Picnic Technologies B.V.
Amsterdam, Netherlands
Senior
Java
Amazon Web Services (AWS)
+1
Matching moments
02:49 MIN
Using AI to overcome challenges in systems programming
AI in the Open and in Browsers - Tarek Ziadé
03:31 MIN
The value of progressive enhancement and semantic HTML
WeAreDevelopers LIVE – You Don’t Need JavaScript, Modern CSS and More
03:58 MIN
Making accessibility tooling actionable and encouraging
Developer Time Is Valuable - Use the Right Tools - Kilian Valkhof
08:07 MIN
Exploring modern JavaScript performance and new CSS features
WeAreDevelopers LIVE – AI, Freelancing, Keeping Up with Tech and More
01:15 MIN
Crypto crime, EU regulation, and working while you sleep
Fake or News: Self-Driving Cars on Subscription, Crypto Attacks Rising and Working While You Sleep - Théodore Lefèvre
02:33 MIN
Why you might not need JavaScript for everything
WeAreDevelopers LIVE – You Don’t Need JavaScript, Modern CSS and More
04:57 MIN
Increasing the value of talk recordings post-event
Cat Herding with Lions and Tigers - Christian Heilmann
04:09 MIN
The emerging market for fixing AI-generated code
Devs vs. Marketers, COBOL and Copilot, Make Live Coding Easy and more - The Best of LIVE 2025 - Part 3
Featured Partners
Related Videos
Data-Oriented Programming - Version 1.1
Nicolai Parlog
Tackling Complexity With Functional Programming And Kotlin
Georg Dresler
Modern Java 25
Ron Veen
Modern Java: This is not your father's Java anymore
Ron Veen
Java Sealed Classes vs. Kotlin Sealed Classes #Slideless
Lothar Schulz
Typed Security: Preventing Vulnerabilities By Design
Michael Koppmann
Using Java 17 latest features in real world projects
Ron Veen
Best of Java 15 and beyond—my favorite features
Michael Inden
Related Articles
View all articles

.gif?w=240&auto=compress,format)

From learning to earning
Jobs that call for the skills explored in this talk.









ADVERGY GmbH
Paderborn, Germany
Remote
€80-100K
Java
Software Architecture