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

前端 未结 4 1797
日久生厌
日久生厌 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 03:03

    You could use a helper function as below:

    @Suppress("UNCHECKED_CAST")
    fun  genericArrayOfNulls(size: Int): Array {
        return arrayOfNulls(size) as Array
    }
    

提交回复
热议问题