in ``` val A = StringBuilder(string = "") val B = ...
# announcements
s
in
Copy code
val A = StringBuilder(string = "")
val B = StringBuilder(content = "")
what is the difference between
string
and
content
, like do both do the exact same thing?
t
I don’t see a constructor with that signature
s
but looking at the definition on my machine (Kotlin/JVM) it’s just a typealias for the java stringbuilder, which doesn’t define a
content
param
t
Unless I’m missing something I still don’t see a constructor takes 2 strings called
content
and
string
s
Looks like its for Kotlin/js?
s
Copy code
val A = StringBuilder(string = "")
val B = StringBuilder(content = "")
s
ahh, I think that might be what it is
there’s a StringBuilder ctor that takes a CharSequence called
content
that’s on Common, though
StringBuilder(content: String)
is just a JS thing it looks like
Copy code
StringBuilder(content: CharSequence)
StringBuilder(string: String)
for everyone else
s
I've been confused more than a few times by the inclusion of
js
stuff in the docs.
s
yeah, I personally only use kotlin/jvm so the docs have definitely tripped me up ’cause I forget to look at the indicators
s
but whats the difference between the two
s
One constructor takes a CharSequence, the other a String
s
other than their types
as if they are named differently then they gotta to something different right?
s
I mean, the CharSequence ctor probably just, does whatever it needs to do to load the chars in the CharSequence into whatever mechanism stores string data
maybe that’s a conversion to String?
the parameters are named differently likely because, well, you don’t want to call a CharSequence that isn’t necessarily a
String
,
string
content
is a fine, more generic name
s
then why not name both as
content
lol
s
convention, probably
the java ctor takes a param named
str
,
string
is a natural extension of that
s
ok lol
s
the
content
param makes it noticeable that that constructor takes in not String, but instead anything that implements CharSequence
s
what does
ensureCapacity
do
s
“lol”
I’m not sure, tbh, it’s not documented and only available on Native
Are you writing K/N?
s
yes
s
It may be an allocation thing, but you might be better served asking nicely in #C3SGXARS6
s
ok
k
Java has it too, I'm not sure why they didn't include that in the Kotlin version.