初始化空的 ByteArray [英] Initialize empty ByteArray

查看:29
本文介绍了初始化空的 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆