kotlin - Kotlin ... 在函数参数中,例如来自 Java - setFilterById(long... ids)
问题描述
例如,在 Android DownloadManager 类中,有一个用 Java 声明的函数:
private long[] mIds = null;
public Query setFilterById(long... ids) {
mIds = ids;
return this;
}
在 Java 中,我可以将一个 long 值数组传递给它,并且效果很好。在 Kotlin 中,当我尝试:
val mEnqued = ArrayList<Long>()
// collect download ids to mEnqued...
query.setFilterById(mEnqued.toLongArray())
// or try to pass an array of long created in any other way...
// it will take: query.setFilterById(7L, 15L, 234L) - but it's useless
Kotlin 编译器抱怨“类型不匹配:推断的类型是 LongArray 但预计为 Long”......我还能如何将 long Id 值的列表或数组传递给这个函数?我不能直接在源代码中输入它们,因为事先我不知道它们中有多少,或者它们的值是什么?Kotlin 在这里似乎非常有限或“大脑受损”......
解决方案
推荐阅读
- java - 如何将显示传递给 qsub 命令?
- qt - 在“AppListView”中是加载器应该使用“SimpleRow”加载组件的空白位置
- postman - 我可以在 newman 中使用邮递员集合变量吗?
- r - R - 如何在 R 中绘制核心数据?
- sql - 如何在 postgresql 中存储多边形数据?
- gradle - asciidoctor 在 gradle 中未运行(或未正常运行)
- php - 未知单词来自 wordpress 中的页面
- java - 为什么在内部存储而不是外部存储中创建新文件夹?
- python - Python Speech_recognition.UnknownValueError
- javascript - 从客户端站点自动预填充网络表单