How to overcome "same JVM signature" error when implementing a Java interface?

IMHO most readable combination is field + explicit interface implementation by the single-expression function (combination of @Renato Garcia's and @Steven Spungin's answers):

Java:

public inteface SomeInterface {
    String getFoo();
}

Kotlin:

class Implementation(@JvmField val foo: String) : SomeInterface {
    override fun getFoo() = foo
}

The annotation feature of Kotlin named @JvmName will solve the duplication problem in Java and Kotlin when having the same signature.

fun function(p: String) {
   // ...
}

// Signature: function(Ljava/lang/String)

With the use of JvmName will be:

@JvmName("functionOfKotlin")
fun function(p: String) {
   // ...
}

// Signature: functionOfKotlin(Ljava/lang/String)

Making that variable private solves the problem.

public class KotlinClass(private val name: String?) : JavaInterface


You could use @JvmField for instructs the compiler not generate getter/setter, and you can implement your setters and getters. With this your code work well in Java (as attribute getter/setter) and Kotlin as property

Example: JAVA:

public interface Identifiable<ID extends Serializable> 
{
   ID getId();
} 

KOTLIN:

class IdentifiableImpl(@JvmField var id: String) :Identifiable<String> 
{
   override fun getId(): String 
   {
       TODO("not implemented")
   }
}

Tags:

Kotlin