In Kotlin 0.12.1230 it appears that deprecated APIs are blocking the use of their replacements.
For example, the compiler complains about the following snippet because it "cannot choose among... candidates without completing type inference"
val seq = sequenceOf("1")
val first = seq.firstOrNull()
The candidates are Sequence<T>.firstOrNull
and Stream<T>.firstOrNull
both of which have identical signatures and Sequence<T>
extends Stream<T>
. Furthermore, Stream<T>
is deprecated in favor of Sequence<T>
.
Attempting to resolve the type inference ambiguity, like you see below, results in the compiler complaining about "overload resolution ambiguity".
val seq = sequenceOf("1")
val first = seq.firstOrNull<String?>()
Is there any way to resolve the ambiguity while we wait for deprecated APIs to disappear entirely?
It seems that casting to the least specific type, in this case the deprecated type Stream<T>
, accomplishes it, but now my code explicitly depends on a deprecated type when I have no desire to do so:
val seq = sequenceOf("1")
val first = (seq as Stream<String>).firstOrNull()
Hopefully there is a better way?
This seems to be caused by multiple conflicting versions of the Kotlin stdlib on my classpath (caused by a long standing defect in Gradle IntelliJ integration). Once they were version conflict resolved, the compiler no longer complains.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With