How to create a generic array filled with nulls in Kotlin?

前端 未结 4 944
太阳男子
太阳男子 2021-02-14 02:07

I tried this, and the code didn\'t compile.

class GenericClass() {
    private var arr : Array? = null

    {
        arr = Array(10,          


        
4条回答
  •  逝去的感伤
    2021-02-14 02:51

    method

    val array : Array = kotlin.arrayOfNulls(size)
    

    from docs

    /**
    *Returns an array of objects of the given type with the given [size],
    *initialized with null values.
    */
    public fun  arrayOfNulls(size: Int): Array
    

提交回复
热议问题