Andreas Unterweger
12/19/2019, 3:27 PMinterface RequestAuth {
fun header(): Pair<String, String>
}
val instance = object : RequestAuth {
override fun header(): Pair<String, String> = "name" to "value"
}
cant this be done more more concisely? sth like
val instance = object : RequestAuth { "name" to "value" }
diesieben07
12/19/2019, 3:29 PMinterface RequestAuth {
fun header(): Pair<String, String>
companion object {
inline operator fun invoke(crossinline body: () -> Pair<String, String>) = object : RequestAuth {
override fun header() = body()
}
}
}
marstran
12/19/2019, 3:29 PMfun interface
that will work as a SAM-interface. Then you can do this:
fun interface RequestAuth {
fun header(): Pair<String, String>
}
val instance: RequestAuth = { "name" to "value" }
marstran
12/19/2019, 3:29 PMAndreas Unterweger
12/19/2019, 3:30 PM