56477f0af8
Load immutable flexible upper bound for 'Iterable<? super T>' We load 'Collection<? super CharSequence>' as 'MutableCollection<in CharSequence>' instead of 'MutableCollection<in CharSequence>..Collection<*>' because it's obviously not typesafe to use any 'Collection<*>' as argument for such type. But there'se nothing bad with loading 'Iterable<? super CharSequence>' as 'MutableIterable<*>..Collection<*>'. Same for other declarations that have covariant mutable representation (currently Iterator, ListIterator). Also there are useful use-cases when it's neccessary to use 'Iterable<*>' as an argument for parameter with type 'Iterable<? super T>' (see matchers.kt test). NB: Star-projections appear in examples because types like 'Collection<in CharSequence>' with conflicting use-site projections are invalid in Kotlin, but they are valid in Java.
21 lines
445 B
Kotlin
Vendored
21 lines
445 B
Kotlin
Vendored
// FILE: A.java
|
|
import java.util.*;
|
|
public class A {
|
|
public static void foo(Iterable<? super CharSequence> x) {}
|
|
public static void bar(Iterator<? super CharSequence> x) {}
|
|
}
|
|
|
|
// FILE: main.kt
|
|
|
|
fun test(x: List<String>, y: List<*>, z: MutableList<*>, w: MutableList<in CharSequence>) {
|
|
A.foo(x)
|
|
A.foo(y)
|
|
A.foo(z)
|
|
A.foo(w)
|
|
|
|
A.bar(x.iterator())
|
|
A.bar(y.iterator())
|
|
A.bar(z.iterator())
|
|
A.bar(w.iterator())
|
|
}
|