代码之家  ›  专栏  ›  技术社区  ›  Jack Guo

Kotlin将列表转换为vararg

  •  6
  • Jack Guo  · 技术社区  · 7 年前

    我有类型的输入数据 List<UnitWithComponents>

    class UnitWithComponents {
        var unit: Unit? = null
        var components: List<Component> = ArrayList()
    }
    

    我想将数据转换为 vararg 属于 Unit

    目前我正在做 *data.map { it.unit!! }.toTypedArray() . 有更好的方法吗?

    1 回复  |  直到 7 年前
        1
  •  2
  •   Alexey Romanov    7 年前

    it.unit null