1.4.30 kotlin language feature Sealed interfaces

hello android developer.

Is there a way to literally use the “Sealed interfaces” well?

Can you clarify your question?
What stops you from using “Sealed interfaces” well?

I tested it locally and it worked well for me. Until a release of version 1.5 you only need to put those properties into your config:

tasks.withType<KotlinCompile> {
	kotlinOptions {
		languageVersion = "1.5"
		apiVersion = "1.5"
	}
}

and then it should work:

sealed interface CustomList
class List1 : CustomList
class List2 : CustomList
enum class EnumList : CustomList {
	LIST3, LIST4
}

fun handleList1(list: CustomList): Int = when (list) {
	is List1 -> 1
	is List2 -> 2
	EnumList.LIST3 -> 3
	EnumList.LIST4 -> 4
}

fun handleList2(list: CustomList): Int = when (list) {
	is List1 -> 1
	is List2 -> 2
	is EnumList -> 3 + 4
}
2 Likes