Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Initialize empty ByteArray

How do you initialize an empty ByteArray in Kotlin? Whenever I try to do this:

val asdfasdf : ByteArray

I get told that I need to initialize asdfasdf when I try to use it later here:

mVisualizer.getWaveForm(asdfasdf)

Variable 'asdfasdf' must be initialized

like image 783
Jake Choi Avatar asked Mar 08 '26 07:03

Jake Choi


1 Answers

The easiest way to make a ByteArray in Kotlin in my opinion is to use byteArrayOf(). It works for an empty ByteArray, as well as one which you already know the contents of.

val nonEmpty = byteArrayOf(0x01, 0x02, 0x03)
var empty = byteArrayOf()
empty += nonEmpty
like image 72
Chee-Yi Avatar answered Mar 09 '26 20:03

Chee-Yi