How to call String.getBytes()?

I want to call String.getBytes(), but the editor says the method is unknown & the compiler gives me an unresolved reference.

This seems like a bug.

KT-7995 may be related, but getBytes() itself isn’t deprecated (although one of its overloads is deprecated).

Is there a workaround?

Thanks,
Neil

2 Likes

Use String.toByteArray() extension: toByteArray - Kotlin Programming Language

3 Likes

Thanks Ilya.

Was this method purposefully hidden?

4 Likes