I'm having a strange issue with extending a Kotlin...
# announcements
m
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
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
@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:
Copy code
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
Oh, I see, yes, you should add @JvmSuppressWildcards in Foo : Iterable