Kotlin: How to work with List casts: Unchecked Cast: kotlin.collections.List

前端 未结 5 746
自闭症患者
自闭症患者 2020-12-07 10:51

I want to write a function that returns every item in a List that is not the first or the last item (a via point). The function gets a generic List<*&g

5条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-07 11:45

    I made a little variation to @hotkey answer when used to check Serializable to List objects :

        @Suppress("UNCHECKED_CAST")
        inline fun  Serializable.checkSerializableIsListOf() =
            if (this is List<*> && this.all { it is T })
              this as List
            else null
    

提交回复
热议问题