Oleg Sokolov
Oleg Sokolov

Reputation: 1143

How to make a ByteArray unmodified in Kotlin

Is there a way to make ByteArray unmodifiable in Kotlin?

Like with collections Collections.unmodifiableList(byteList)

Upvotes: 1

Views: 425

Answers (1)

yole
yole

Reputation: 97148

A ByteArray maps to byte[] when compiled to the JVM, and the JVM has no support for unmodifiable arrays. You can wrap a ByteArray into a class that holds the array in a property and does not provide any APIs for modifying it.

Upvotes: 3

Related Questions