typealias TeardownLogic = () -> Unit fun onCancel(teardown : TeardownLogic){ }
private typealias OnDoggoClick = (dog: Pet.GoodDoggo) -> Unit val onClick: OnDoggoClick
typealias TeardownLogic = () -> Unit //or typealias TeardownLogic = (exception: Exception) -> Unit
fun onCancel(teardown : TeardownLogic){ // can’t easily see what information we have // available in TeardownLogic }
typealias Doggos = List<Pet.GoodDoggo>
fun train(dogs: Doggos){ … }
Chiediti se l'uso di un typealias rende il tuo codice più comprensibile.
typealias AVD = AnimatedVectorDrawable
import android.graphics.drawable.AnimatedVectorDrawable as AVD
import io.plaidapp.R as appR
import io.plaidapp.about.R
expect annotation class Test
actual typealias Test = org.junit.Test
// Kotlin typealias Doggos = List<Pet.GoodDoggo> fun train(dogs: Doggos) { … }
// Decompiled Java code public static final void train(@NotNull List dogs) { … }
I typealias non introducono nuovi tipi.
fun play(dogId: Long)
typealias DogId = Long
fun pet(dogId: DogId) { … }
fun usage() { val cat = Cat(1L) pet(cat.catId) // compiles }