https://kotlinlang.org logo
#compose
Title
# compose
e

eygraber

02/16/2023, 6:45 PM
Is there any way to mark
CharSequence
as being stable? I'm using it as a way to pass around either
String
or
AnnotatedString
.
r

romainguy

02/16/2023, 7:21 PM
I don’t think that would work since a
StringBuilder
is a
CharSequence
for instance but changes are not observable
e

eygraber

02/16/2023, 7:24 PM
True, but in my use cases I'm always limiting it to a
String
or
AnnotatedString
z

Zach Klippenstein (he/him) [MOD]

02/17/2023, 5:36 AM
You could wrap it in a stable holder class
e

eygraber

02/17/2023, 2:42 PM
I tried that but it made the API not as great + I would've had to spread it out over a bunch of libraries. I ended up going with overloads of all my generic composable that deal with text, which isn't great either, but at least the API is nicer
z

Zach Klippenstein (he/him) [MOD]

02/17/2023, 6:56 PM
Ah yes if this is for a public api, tricking the compiler into treating CharSequence as would be especially bad because you couldn’t prevent consumers from passing in non-stable objects.
e

eygraber

02/17/2023, 6:58 PM
I'd say it's more of an "internal" API. We also check the CharSequence to make sure that it's a String or AnnotatedString and throw otherwise.
136 Views