Maciej Pigulski
12/28/2022, 11:32 AMMaciej Pigulski
12/28/2022, 11:32 AMfun interface Mapper<T> {
suspend fun map(value: String): T
}
fun <R> test(mapper: Mapper<R> = Mapper { it }) {
}
Maciej Pigulski
12/28/2022, 11:33 AMefemoney
12/28/2022, 11:45 AMMapper<out T>
efemoney
12/28/2022, 11:51 AMtest<Int>() { ... }
, then that means the compiler allowed code which is impossible to be calledefemoney
12/28/2022, 11:54 AMmapper
parameter then you should represent it as Mapper<*>
efemoney
12/28/2022, 11:55 AMMapper { it as R }
which will generate a (very correct) warningMaciej Pigulski
12/28/2022, 12:55 PMMaciej Pigulski
12/28/2022, 12:57 PMMaciej Pigulski
12/28/2022, 12:58 PMMaciej Pigulski
12/28/2022, 12:59 PMMaciej Pigulski
12/28/2022, 1:00 PMfun interface Mapper<T> {
suspend fun map(value: String): T
}
fun <R> test(mapper: Mapper<String> = Mapper { it }) {
}
Maciej Pigulski
12/28/2022, 1:00 PMefemoney
12/28/2022, 4:28 PMInt
by writing test<Int>() { ... }
, this means that the parameter mapper
should be of type Mapper<Int>
but remember in the default argument of that function (if kotlin compiler did not flag this case) you would be assigning Mapper<String> to Mapper<Int> which would be a runtime failureefemoney
12/28/2022, 4:30 PM