https://kotlinlang.org logo
s

SirNapkin1334

05/11/2021, 12:47 AM
Hello, I'm getting a very strange error when trying to call a function. In a certain function I've written, I've wrapped my Kotlin Strings in Java Strings to benefit from the significant speedup in
java.lang.String#repeat(int)
compared to
kotlin.text.repeat(CharSequence, int)
. When I run the code in IJ, it works fine, when I call the function from Java for testing purposes, it works fine, but when I compile the jar and run it via
java -jar
, it throws a
NoSuchMethodError
, saying that there is no method
java.lang.String#repeat(int)
. Does anyone know the cause?
The function I'm calling uses Java strings so:
Copy code
kt
```fun cls(size: Int) = print(java.lang.String(
	java.lang.String(" ").repeat(size * 2 + 3) + "[1F"
).repeat(size + 2))
Ooops, looks like Slack doesn't support syntax highlighting for code blocks
if you are running with an older Java you can't use String.repeat
also, Kotlin strings are Java strings, you don't need to wrap
s

SirNapkin1334

05/11/2021, 12:52 AM
ah, oops, i had forgotten to set my system java back version to 15!
e

ephemient

05/11/2021, 12:53 AM
Copy code
(" " as java.lang.String).repeat(10)
s

SirNapkin1334

05/11/2021, 12:54 AM
ah, thanks, i probably should have tried that.
e

ephemient

05/11/2021, 12:55 AM
no worries, the way in which platform types are aliased can be a bit confusing
s

SirNapkin1334

05/11/2021, 12:57 AM
my question is, why they don't use the java implementation of that if it's available
i benchmarked it and the speedup is on the order of 5x
e

ephemient

05/11/2021, 12:58 AM
kotlin-stdlib-jvm only depends on Java 6
💯 1
s

SirNapkin1334

05/11/2021, 12:59 AM
ah
6 Views