Hi there! There are few very similar extension met...
# stdlib
e
Hi there! There are few very similar extension methods for converting
String
to
ByteArray
in sdlib:
Copy code
String.toByteArray(charset: Charset = Charsets.UTF_8): ByteArray
and
Copy code
String.encodeToByteArray(): ByteArray
Why so? Why having both? The second one looks redundant as it • doesn't allow to provide charset • has longer name, while clearness is the same as with shorter version
p
The second one is multiplatform.
e
I'm not good at Kotlin stdlib yet. Is this how it's written? So the half of the stdlib is not multiplatform, and the other half of the stdlib (with very similar names, like
toByteArray
-
encodeToByteArray
) is?
h
You can check the API docs, the colored dots indicate the supported platforms for each method. You can also hide platforms with the buttons of the same color at the top. The
toByteArray
method can't be multiplatform, because it uses a Java
Charset
as a parameter type. That's why the second method exists, I guess. Methods which don't reference platform-specific stuff are usually multiplatform.
e
So in some future we (I mean Jetbrains) will end up with stdlib that is entirely (almost?) multiplatform? Is that one of the goal?
x
Making stdlib functions available suitable for multiplatform doesn't imply having duplicated signatures for all cases. For most of them it'll just be an implementation detal that's abstracted for the caller
a
Shouldn’t one should be deprecated? Also what is the way to pass the
Charset
in
String.encodeToByteArray(): ByteArray
method?
p
As I know, there is no multiplatform solution for charsets yet.