Answer the question
In order to leave comments, you need to log in
How to prevent Any type inference when using interface with "out X" parameter in Kotlin?
I'll show you with an example:
open class Foo(var barInt: Int)
// public interface KProperty1<T, out R> : KProperty<R>, (T) -> R
fun <E : Foo, T> test(field: kotlin.reflect.KProperty1<E, T>, value: T): T = TODO()
fun main(args: Array<String>) {
test(Foo::barInt, 123) // ок
test(Foo::barInt, "NotInt") // тоже ок! Тип T = Any, но я бы хотел ошибку компиляции
}
Answer the question
In order to leave comments, you need to log in
The answer why this can not be done yet, and a temporary solution is written here:
https://discuss.kotlinlang.org/t/how-prevent-type-...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question