mirror of
https://github.com/jlengrand/kotlin.git
synced 2026-05-09 00:21:47 +00:00
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.
This commit is contained in:
13
compiler/testData/codegen/boxWithJava/collections/readOnlyList/J.java
vendored
Normal file
13
compiler/testData/codegen/boxWithJava/collections/readOnlyList/J.java
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
import java.util.*;
|
||||
|
||||
public class J {
|
||||
|
||||
private static class MyList<E> extends KList<E> {}
|
||||
|
||||
public static String foo() {
|
||||
Collection<String> collection = new MyList<String>();
|
||||
if (!collection.contains("ABCDE")) return "fail 1";
|
||||
if (!collection.containsAll(Arrays.asList(1, 2, 3))) return "fail 2";
|
||||
return "OK";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user