Junior
What is 'typealias' in Kotlin and how is it used?
sobes.tech AI
Answer from AI
typealias in Kotlin allows creating aliases for existing types. This improves code readability and simplifies working with long or complex types without creating new types.
For example, if you have a complex type, such as a function with multiple parameters, you can give it a meaningful name:
typealias ClickHandler = (Int, String) -> Unit
fun setOnClickListener(handler: ClickHandler) {
// implementation
}
Such an alias helps make the code more understandable and facilitates refactoring, as changing the type only requires updating the alias in one place.