初始化空的 ByteArray [英] Initialize empty ByteArray
问题描述
如何在 Kotlin 中初始化一个空的 ByteArray?每当我尝试这样做时:
val asdfasdf : ByteArray
我被告知,当我稍后在这里尝试使用它时需要初始化 asdfasdf:
mVisualizer.getWaveForm(asdfasdf)
<块引用>
必须初始化变量 'asdfasdf'
您的 val asdfasdf : ByteArray
只是需要初始化的不可变声明.如果你事先知道大小,你可以像这样初始化它 val asdfasdf : ByteArray = ByteArray(10)
但是你可能需要这样的东西 val asdfasdf = arrayListOf<Byte>()代码> 能够动态地向其中添加项目.
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
Your val asdfasdf : ByteArray
is just declaration of immutable that needs to be initialized. If you know size in advance, you can init it like this val asdfasdf : ByteArray = ByteArray(10)
however you probably need something like this val asdfasdf = arrayListOf<Byte>()
to be able add items into it dynamically.
这篇关于初始化空的 ByteArray的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!