https://kotlinlang.org logo
Title
m

mbstavola

12/14/2017, 5:20 AM
I'm having a strange issue with extending a Kotlin class that implements Iterable. It seems as though when viewed from Java, the implementation clashes with the
java.util
equivalent. Not really too sure what's up!
g

gildor

12/14/2017, 5:35 AM
Because Kotlin generates covariant generic by default
<? extends String>
You can use it on java side or disable such behaviour using JvmSuppressWildcards https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.jvm/-jvm-suppress-wildcards/index.html
m

mbstavola

12/14/2017, 5:44 AM
@JvmSuppressWildcards
worked for me when I tagged the second generic parameter for Map. Thanks! I am a little confused as to what you mean by "use it on the Java side" though, since trying to something like:
public Iterator<Map<String, ? extends String>> iterator() {
    return super.iterator();
}
gives you the same error as before
I can't see any other way I'd be able to fix this issue from the Java side since all that class is doing is extending the Kotlin class 😞
g

gildor

12/14/2017, 5:58 AM
Oh, I see, yes, you should add @JvmSuppressWildcards in Foo : Iterable