Hello, I'm getting a very strange error when tryin...
# announcements
s
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
ah, oops, i had forgotten to set my system java back version to 15!
e
Copy code
(" " as java.lang.String).repeat(10)
s
ah, thanks, i probably should have tried that.
e
no worries, the way in which platform types are aliased can be a bit confusing
s
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
kotlin-stdlib-jvm only depends on Java 6
💯 1
s
ah