Brian Donovan
09/24/2021, 3:42 PMKirill Grouchnikov
09/24/2021, 3:44 PMJoffrey
09/24/2021, 3:44 PMKirill Grouchnikov
09/24/2021, 3:44 PMKirill Grouchnikov
09/24/2021, 3:45 PMBrian Donovan
09/24/2021, 3:45 PMRob Elliot
09/24/2021, 4:33 PMPaul Griffith
09/24/2021, 4:41 PM@JvmOverloads
and the compiler will spit out, as the name implies, sequential JVM overloads with your default arguments specified. Nice for Java consumers of Kotlin code, otherwise unnecessaryJoffrey
09/24/2021, 4:58 PMephemient
09/24/2021, 5:19 PMCLOVIS
09/24/2021, 7:40 PM@JvmName
, but on Kotlin/JS it's supported by default.Rob Elliot
09/24/2021, 10:39 PMpackage bar
@JvmName("foo1")
fun foo(): String {
println("foo1")
return ""
}
@JvmName("foo2")
fun foo(): Int {
println("foo2")
return 1
}
fun main() {
val x: Int = foo()
}
Error message:
Bar.kt: (3, 1): Conflicting overloads: public fun foo(): String defined in bar in file Bar.kt, public fun foo(): Int defined in bar in file Bar.kt
Same in a kotlin/js IR project using node.js.ephemient
09/25/2021, 12:01 AM@JvmName("fooInt")
fun foo(list: List<Int>)
@JvmName("fooString")
fun foo(list: List<String>)
which would be erased to the same signature without @JvmName
, but it does not allow overloading by return typeCLOVIS
09/25/2021, 7:18 AMephemient
09/26/2021, 2:50 AMfun foo(): String = TODO()
fun <T: String> foo(): T = TODO()
they have the same erased signature on JVM, so Kotlin will disallow that, as well as disallowing other cases even with different type parameters such as
fun <T: String> foo(bar: Any): T = TODO()
fun <U, V : Any> foo(bar: V): U = TODO()
even though they have different JVM signatures