【发布时间】:2018-05-13 17:46:43
【问题描述】:
我在 Kotlin REPL 中尝试过这些
var listA = listOf(null ,null)
var listB = [null, null]
第一行按预期工作正常。在显示 listA 时,我得到:
[null, null]
第二行抛出如下错误:
error: cannot use 'Nothing?' as reified type parameter
var listB = [null,null]
^
error: unsupported [Collection literals outside of annotations]
var listB = [null,null]
^
error: unsupported [Array<Nothing> in return type is illegal]
var listB = [null,null]
^
当我尝试对非空类型进行相同操作时, 即
var listC = [1,2]
我收到此错误:
error: unsupported [Collection literals outside of annotations]
var listC = [1,2]
^
我是 Kotlin 的新手。有人可以解释一下这里发生了什么吗?
【问题讨论】:
标签: kotlin