Does Kotlin support upper / lower type bounds in a covariance setting. Eg, I want to say
class Foo<out T> {
fun or<U of T or greater>(other: U): <U> = ...
}
which in Scala would be
class Foo[+T] {
def or[U >: T](other: U): U = ...
}
But the compiler doesn't seem to like this, it complains about the covarianceness of the type parameter T.
Kotlin does not support lower bounds at this point. Sometimes you can get away with defining an extension function instead of a member:
fun <T> Foo<T>.or(other: T): T = ...
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