Lothar Schulz

Java Sealed Classes vs. Kotlin Sealed Classes #Slideless

What if you never had to write another null check for an API response? See how sealed classes in Java and Kotlin make it possible.

Java Sealed Classes vs. Kotlin Sealed Classes #Slideless
#1about 2 minutes

Introducing sealed classes in Java 17

Sealed classes restrict which other classes may extend them, giving developers more control over inheritance hierarchies.

#2about 1 minute

Understanding Kotlin sealed classes as super enums

Kotlin's sealed classes act like enums that can hold state, making them powerful containers for different types of data.

#3about 13 minutes

Refactoring Kotlin code to eliminate nulls with sealed classes

A live coding demo shows how to replace nullable return types with a sealed class to explicitly handle success and failure cases.

#4about 11 minutes

Implementing sealed classes in Java to handle API results

This live coding example demonstrates creating a Java sealed class with final subclasses to manage success and failure states from an API call.

#5about 3 minutes

Using Java sealed interfaces with records for conciseness

Code is refactored from sealed classes to sealed interfaces implemented by records, significantly reducing boilerplate code.

#6about 3 minutes

Applying pattern matching in Java with switch expressions

The if-instanceof chain is replaced with a modern switch expression for exhaustive and more readable pattern matching.

#7about 3 minutes

Conclusion on Java vs Kotlin sealed class parity

Sealed classes in both Java and Kotlin are now functionally on par, so language choice can be based on other factors.

Related jobs
Jobs that call for the skills explored in this talk.

asasd

Expire

Remote
Junior

d

Saby Company
Delebio, Italy

Junior

test

Milly
Vienna, Austria

Intermediate

Featured Partners

Related Articles

View all articles
BB
Benedikt Bischof
Using Java 17 latest features in real world projects
Welcome to this issue of the WeAreDevelopers Live Talk series. This article recaps an interesting talk by Ron Veen who introduced the audience to some of the most interesting features that got added to the Java language.About the speaker:Ron is a hig...
Using Java 17 latest features in real world projects
MI
Michael Inden
Modern Java Switch Expressions
In this blog, I will cover some improvements of switch. The old syntax dates back to the early day of Java, and its handling is a bit cumbersome. Let's look at the newer, slightly modified syntax for switch, called Switch Expressions. With it, case d...
Modern Java Switch Expressions
MI
Michael Inden
Modern Java Records
In this blog, I will present Records, one of my favorite features of modern Java. Records represent a simplified form of classes whose methods are implicitly derived from the attributes defined as constructor parameters. A record constitutes a collec...
Modern Java Records

From learning to earning

Jobs that call for the skills explored in this talk.

Java Developer

Java Developer

MyPrivacy
Vienna, Austria

Intermediate
Java
JUnit
Kotlin