Skip to content
Advertisement

Java Equivalent of Kotlin Sealed Class Type Detection

I want to access information from this Kotlin class in Java. It is being imported via a Gradle library.

Sealed Class:

JavaScript

In Java, I’m trying to determine whether it is of type Success or Error, and if possible, I want to be able to retrieve the “statusCode” from it. I know in Kotlin it’d be preferable to use the ‘when’ logic in Kotlin, but I haven’t been able to find a suitable replacement for it.

Advertisement

Answer

The best you can do in Java is

JavaScript
Advertisement