Inherited platform declarations clash


When trying to extend the Java class “JavaSubClass” I get the following compiler errors:

Class ‘KotlinClass’ is not abstract and does not implement abstract base class member
public abstract fun setCollection(collection:(Mutable)Collection<String!>!): Unit defined in JavaSubClass

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

Here’s my setup:

import java.util.Collection;

public interface JavaInterface {
    void setCollection(Collection<String> collection);

public class JavaClass {
    public void setCollection(Collection collection){}

public class JavaSubClass extends JavaClass implements JavaInterface {}

class KotlinClass : JavaSubClass()

Now there seem to be multiple possible workarounds:

  • In the JavaClass setCollection method specify the type to use Collection<String> instead of just Collection

  • In JavaSubClass override setCollection of JavaClass

    public void setCollection(Collection collection) {

What if everything but the Kotlin code is third-party? Well you still can create a new Java class which extends JavaSubClass, override setCollection and let the Kotlin class extend this new one.

Why do the Java and Kotlin compilers handle this case differently?