TheOnlyTails
02/16/2022, 7:32 PMval list = listOf<<T>(x: T) -> Unit>()
Vampire
02/16/2022, 7:55 PMT
is?Joffrey
02/16/2022, 7:59 PMAny
or Any?
instead of T
Tim Oltjenbruns
02/16/2022, 7:59 PMval list: List<(Int) -> String> = listOf<(Int) -> String>({ x: Int -> ""})
Without generics this is the fully-qualified way to define a list here
If you had this inside a class that had a generic, this is an option.
class MyClass<T> {
val list: List<(T) -> String> = listOf<(T) -> String>({ x: T -> ""})
}
Tim Oltjenbruns
02/16/2022, 8:00 PMfun <T> myFunction(): List<(T) -> String> = listOf<(T) -> String>({ x: T -> ""})
val list: List<(Int) -> String> = myFunction<Int>()
Tim Oltjenbruns
02/16/2022, 8:03 PMVampire
02/16/2022, 8:03 PMVampire
02/16/2022, 8:04 PMIf you want to create a list of functions that accept any type of arguments, useThis actually also does not work:orAny
instead ofAny?
T
val list = listOf<(Any) -> Unit>({ s: String -> Unit }, { s: Exception -> Unit })
Joffrey
02/16/2022, 8:05 PMAny
Tim Oltjenbruns
02/16/2022, 8:05 PMTim Oltjenbruns
02/16/2022, 8:05 PMVampire
02/16/2022, 8:08 PMMatthias Geisler
02/16/2022, 8:25 PMTim Oltjenbruns
02/16/2022, 8:28 PMMatthias Geisler
02/16/2022, 9:00 PMval list = listOf<Function1<*, Unit>>(
{ x: Int -> x+2 }
)
However the caller of the list needs to know then which index holds which lambda.Sam
02/17/2022, 4:12 PM