I am writing two extension functions for the same class:
class Something { ... }
They lo
Kotlin has the @JvmName annotation specifically for this type of use case. In Kotlin, there isn't a problem because it knows the difference between the methods. But the Java compatible byte code would have a conflict for naming since the generics erased signatures would be identical.
Therefore you need to use this annotation to control the name from the perspective of Java and the JVM. Your Kotlin code will not see this alternative name and will use the name as you intended.
Change your code to:
@JvmName("somethingIntToJson") fun Something.toJson(): String = ...
@JvmName("somethingDoubleToJson") fun Something.toJson(): String = ...
From Kotlin, use normally:
val someIntyThing = Something(194)
val json = someIntyThing.toJson()