Files
kotlin/compiler/testData/codegen/boxWithJava/collections/readOnlyList/readOnlyList.kt
Denis Zharkov 20cbceb56d Add temporary hack for wildcards in Collections
By default we would render 'MutableCollection<String>.addAll(Collection<String>)' as
'(LCollection<String>;)' (without wildcard) because String is final and
effectively it's the same as '(LCollection<? extends String>;)'.

But that's wrong signature in a sense that java.util.Collection has different
signature: '(LCollection<? extends E>)'.

Actually the problem is much wider than collections,
it concerns any Java code that uses Kotlin classes with covariant
parameters without '? extends E' wildcards.

Temporary solution is just to hardcode/enumerate builtin methods
with special signature.
2015-12-01 08:20:59 +03:00

40 lines
1.0 KiB
Kotlin
Vendored

open class KList<E> : List<E> {
override val size: Int
get() = throw UnsupportedOperationException()
override fun isEmpty(): Boolean {
throw UnsupportedOperationException()
}
override fun contains(o: E) = true
override fun containsAll(c: Collection<E>) = true
override fun iterator(): Iterator<E> {
throw UnsupportedOperationException()
}
override fun get(index: Int): E {
throw UnsupportedOperationException()
}
override fun indexOf(element: E): Int {
throw UnsupportedOperationException()
}
override fun lastIndexOf(element: E): Int {
throw UnsupportedOperationException()
}
override fun listIterator(): ListIterator<E> {
throw UnsupportedOperationException()
}
override fun listIterator(index: Int): ListIterator<E> {
throw UnsupportedOperationException()
}
override fun subList(fromIndex: Int, toIndex: Int): List<E> {
throw UnsupportedOperationException()
}
}
fun box() = J.foo()