why do i get `java.lang.ClassFormatError: Duplicat...
# announcements
s
why do i get
java.lang.ClassFormatError: Duplicate method name&signature in class file FileKt
in https://pl.kotl.in/tLfGFlvku
r
Because
String.toStringBuilder()
and
Sting?.toStringBuilder()
have the same signature.
s
so that ONLY compiles in kotlin/native?
r
Yes, sorry. They have the same signature on the JVM, which is what you are running on in the playground.
s
;-;
r
To fix it on the JVM, you can use something like
Copy code
@JvmName("toStringBuilderOrNull")
fun String?.toStringBuilder()...
s
ok o.o
r
Or honestly don't define that function.
That way at the use site, if you're using a nullable string, you have to specify
Copy code
myString?.toStringBuilder()
and the usage makes it clear what the expected result is.
s
ok
r
Considering your definition can be rewritten as
Copy code
fun String?.toStringBuilder() = this?.toStringBuilder()
you might as well just use it that way. No reason to define an extra function to save 1 character.
But that's just my opinion.
s
ok
i like having the function directly accessible in auto-completion without needing to put
?
to access it lol