报告实参需要显式转换才能解析为正确声明的重载函数调用。 当前的编译器警告(从 Kotlin 1.6.20 开始提供)将成为 Kotlin 1.8 中的错误。
进度和范围类型 (kotlin.ranges
) 将在 1.9 及更高版本中开始实现 Collection
接口。 此更新将导致重载函数的解析发生变化。 例如,在下面的示例中,test(1..5)
调用将在 Kotlin 1.8 及更早版本中被解析为 test(t: Any)
,而在 Kotlin 1.9 及更高版本中被解析为 test(t: Collection<*>)
。
fun test(t: Any) { }
fun test(t: Collection<*>) { }
fun invoke() {
test(1..5) // 在 1.9 版中 IntRange 会变成 Collection
}
提供的快速修复会捕获 1.8 版及更早版本的编译器特有的行为:
fun test(t: Any) { }
fun test(t: Collection<*>) { }
fun invoke() {
test(1..5) // 在 Kotlin 1.9 之前的版本中解析为 'test(t: T)'
}
在应用快速修复后:
fun test(t: Any) { }
fun test(t: Collection<*>) { }
fun invoke() {
test((1..5) as Iterable<Int>) // 在 Kotlin 1.9 版中解析为 'test(t: T)'
}
从 1.6 版开始,可对 Kotlin 语言级别进行检查。