Files
kotlin-fork/compiler/testData/codegen/boxModernJdk/testsWithJava17/sealed/sealedJavaClassViaKotlinReflection.kt
T
Ilya Chernikov 5d6e2b57a7 Sort sealed class inheritors to ensure reproducible builds with IC
without this sorting the inheritors field in the metadata may depend on
whether some inheritors are compiled in the IC round or not.
2022-03-30 08:35:30 +00:00

22 lines
574 B
Kotlin
Vendored

// WITH_REFLECT
// FILE: Base.java
public sealed class Base permits O, K {}
// FILE: O.java
public final class O extends Base {}
// FILE: K.java
public non-sealed class K extends Base {}
// FILE: main.kt
fun box(): String {
val klass = Base::class
if (!klass.isSealed) return "Error: Base is not sealed"
if (klass.isAbstract) return "Error: Base is not abstract"
return klass.sealedSubclasses.asReversed()
.joinToString("") { it.simpleName ?: "_No name provided_" }
.takeIf { it.isNotBlank() }
?: "_No sealed subclasses found_"
}