Files
kotlin-fork/compiler/testData/diagnostics/tests/j+k/matchers.kt
T
Denis Zharkov 56477f0af8 Fix loading container type from Java
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.
2016-03-21 16:46:46 +03:00

19 lines
384 B
Kotlin
Vendored

// FILE: Assert.java
public class Assert {
public static <T> void assertThat(T actual, Matcher<? super T> matcher) {
}
}
// FILE: Matcher.java
public class Matcher<T> {
public static <T> Matcher<java.lang.Iterable<? super T>> hasItem(T item) {
return null;
}
}
// FILE: main.kt
fun test(x: List<String>) {
Assert.assertThat(x, Matcher.hasItem("abc"))
}