I am trying to extend a third-party Java class with Kotlin but I get this compiler message:
Inherited platform declarations clash: The following declarations have the same JVM signature (setCollection(Ljava/util/Collection;)V):
fun setCollection(collection:(Mutable)Collection<(raw)Any?>!: Unit defined in KotlinClass
fun setCollection(collection:(Mutable)Collection<String!>!): Unit defined in KotlinClass
Whatever I do there is no way to get it compiled with Kotlin code only.
The code which reproduces the situation:
//JavaInterface.class
import java.util.Collection;
public interface JavaInterface {
void setCollection(Collection<String> collection);
}
//JavaBaseClass.class
import java.util.Collection;
public class JavaBaseClass {
public void setCollection(Collection collection){}
}
//JavaSubClass.class
public class JavaSubClass extends JavaBaseClass implements JavaInterface {}
//KotlinClass.kt
class KotlinClass : JavaSubClass()
Java itself does not have this problem. So my guess is that this could be related to platform types (String!
is not Any?
).
Is there an elegant workaround to this problem which preferably doesn't involve writing Java code? Or should this be fixed within the Kotlin compiler itself?