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

前端 未结 4 1795
日久生厌
日久生厌 2021-02-14 02:33

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

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

    {
        arr = Array(10,          


        
4条回答
  •  名媛妹妹
    2021-02-14 02:46

    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
    

提交回复
热议问题